I'm having some trouble with my page. I have moved my site from a host provider to another one, and now i'm having some problems with non-latin characters, for text that comes from db query and for text that is in html/php file.
For text that comes from db someone suggested me to apply this after db connection:
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
and it did the trick, but, now i'm having the same problem for texts that comes from html/php files: instead of ë or ç appears �
I'm sure that should be e trick someone on the server or somewhere else on the configuration.
Hope that you can help me.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
i'm using at the header of my file.
You must have this line in your <head> section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Is the collation of your database where the data is stored in utf8_general_ci?
Maybe there was a problem while transfering the files.
If you are familiar with Linux, try to fix the broken files on your server with recode
(excerpt: "The Recode library converts files between character sets and usages.")
Related
I've got a problem with my charset I guess.
I've called out this line of code on the top of my file.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
when I try to read out an 'ë' it returns these two characters: ë .
I can't figure out what I have to do, to return the accented character.
I also found out it only happens to be when I put the accented character into <h1> tags.
Try adding this extra tag so it looks like this:
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
If the data is in a file (I guess an html file) then this may help: http://www.thedatastudio.net/character_encoding_profile.htm.
What are you reading the file with? As you suggest, I'm sure it's interpreting the file as if it were in a different character encoding.
If you are reading data from mysql database then you can use mysqli_set_charset() for mysqli or if you are using PDO you can try below code.
$dbh = new PDO('mysql:'.$conn, $username, $password);
$dbh->exec("set names utf8");
I am having a strange issue. I have Swedish characters. My charset works fine when in loop and being pulled from mysql using PHP but when I simply enter HTML text Swedish character Å, Ä and Ö it does not work. Currently this is my set Charset:
<meta http-equiv="content-type" content="text/html" charset="ISO-8859-1">
Here is a picture of how it looks in the browser:
Now here is a picture of data being pulled from Mysql (in loop) on the same page:
If this question has been asked before, please direct me to the page. Could it be somethign to do with the actual page encoding?
You should try this:
<meta http-equiv="content-type" content="text/html" charset="UTF-8">
Probably the file itself ist stored in UTF-8.Try and save it as a ANSI file.
In notepad++ this can be done via Encoding > Encode in ANSI in the menubar.
Or try to change the meta tag as already suggested.
I have a website where the web pages feed from the same database and I found that in two webpages that have same queries they interpretate the spanish special characters differently.
I cant really figure out what is wrong as I have stripped out the code which is interpreting the special spanish characters wrong and building it up from the scratch.
This one interpretes the characters well.
http://amragl.com/
This one interpretes the characters wrong.
http://amragl.com/menu.php
They both have the following
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
They both feed from the same database and use same queries.
Does anyone have any idea of how to fix this problem?
Thanks in advance.
--UPDATE-
PEASE SEE THE WORD "GAZPACH" or "AL LIM" to see the difference.
You have both
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
in the same file.
I suggest only using the utf-8 one.
Change iso-8859-1 to utf-8, should fix it.
The menu.php page is rendering with windows-1252 encoding, even tho it has iso-8859-1 set.
Are the menu.php contents coming from a database? If yes, which encoding is the database using?
When i see data as stored on mysql database using phpmyadmin, the characters are stored exactly as é à ç however when i use php to display these data on an html document that has the exact following structure:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
</body>
</html>
I got square instead of accented character, however, i don't have this issue with any accented characters on static content that haven't been loaded from mysql in the same page.
when i see on the source code of the page they seem to be identical! for example:
part of static data on the source code displayed as:
éçà
part of mysql origin data:
éçà
i tried replacing
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
with
<meta http-equiv="Content-Type" content="text/html; charset=windows-1552" />
and as result i got mysql one fixed, static with squares !
any hints?
This is quite common charset issue, you need to set connection encoding manually for MySQL connection (those should be first queries you execute after establishing connection):
SET NAMES utf8;
SET CHARACTER SET utf8;
And also make sure every table has CHARACTER SET set to UTF-8.
Or you could also update server configuration.
Looks like a misconfiguration issue. Most probably your DB or drivers are not using UTF-8.
The fact that the data that comes from the DB shows OK when you change to windows-1552 and the static files do not can mean that your source file is (correctly) in UTF-8, but the data from your DB is arriving in the wrong encoding format.
Whatever is going on, stick to UTF-8.
UPDATE: There is a thread that explains how to automatically set the encoding for the connection:
Change MySQL default character set to UTF-8 in my.cnf?
I keep getting these weird text characters when I display user submitted text. like in the following example below. Is there a way I can fox this using PHP, CSS or something so that the characters are displayed properly?
Here is the problem text.
Problems of �real fonts� on the web. The one line summary:
different browsers and different platforms do �hinting�
Here is my meta tag.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
It's an encoding problem. Make sure you send the correct encoding to the browser. If it's UTF-8, you'll do it like this:
header("Content-type: text/html; charset=utf-8");
Also, make sure that you store the content using the same encoding throughout the entire system. Set your database tables to utf8. If you're using MySQL, run the SET NAMES utf8 query when connecting to make sure you're running in UTF-8.
These weird characters occur when you suddenly switch encoding.
Also, some functions in PHP take a $charset parameter (e.g. htmlentities()). Make sure you pass the correct charset to that one as well.
To make sure that PHP handles your charset correctly in all cases, you can set the default_charset to utf-8 (either in php.ini or using ini_set()).
Set your page to UTF-8 encoding.
Please check with the char-set in header section.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
use this below one:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
or try this one:
htmlentities($str, ENT_QUOTES);
Could be problem with file encoding please check that your files is correctly encoded, saved as "UTF-8 without boom", also if you are saving to database use SET NAMES UTF-8