2

Everytime i get some text to display on a page using php echo, all the inverted comma's are replaced by some stupid question mark signs like this: �

Anyone have any idea why this happens?

Encoding: Page- charset=utf-8 Database- MySQL charset: UTF-8 Unicode (utf8)

Arihant
  • 3,847
  • 16
  • 55
  • 86
  • 1
    What character encoding is your page/database? – Daedalus Mar 02 '13 at 08:38
  • well that's kinda french to me :P Lemme see where i can find the encoding and will get back to you. Must be in the head tag somewhere – Arihant Mar 02 '13 at 08:39
  • the page is charset=utf-8 – Arihant Mar 02 '13 at 08:39
  • And the mysql homepage shows : MySQL charset: UTF-8 Unicode (utf8) – Arihant Mar 02 '13 at 08:41
  • 2
    [The Great Escapism (Or: What You Need To Know To Work With Text Within Text)](http://kunststube.net/escapism/). – DCoder Mar 02 '13 at 08:42
  • Could you try and post the inverted comma here? I would like to see if I can copy it, find out what number it has. – Daedalus Mar 02 '13 at 08:43
  • well if i try to write it's .. it looks like this it�s .. i am not sure whether u are able to see that weird question mark in between (If that's what you're trying to ask) – Arihant Mar 02 '13 at 08:46
  • Well I changed the encoding on my page to the encoding of the database and that worked! But just out of curiosity i would like to know that would it make any difference if i put a code between the text i am storing in a php variable and displaying it? For eg: text text text text text text text text text text text text text text text text text text text t
    text text text text text text text text text text text text text text would it still display the image properly? Also i am using nl2br() for that variable
    – Arihant Mar 02 '13 at 08:52
  • 1
    [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Mar 02 '13 at 09:08

2 Answers2

3

Just matched both the encoding of my page and database. They were different. Made them the same and that worked fine

Arihant
  • 3,847
  • 16
  • 55
  • 86
0

Authough the collation of the database is "utf8-unicode-ci", the connection built by PHP side might use latin1 charset. So you would better check that by

echo $mysqli->character_set_name();

or

echo mysqli_character_set_name ($conn);

To set the charset to utf8, do

mysql_query("SET NAMES 'utf8′", $conn);

or

$mysqli->set_charset("utf8");

Hope it helps.

MeadowMuffins
  • 507
  • 1
  • 5
  • 20