UTF 8 mysql problem with quote character

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

UTF 8 mysql problem with quote character

Post by thinsoldier »

My database collation is utf8_general_ci.
My table collation is utf8_general_ci.
My table's `scope` field collation is utf8_general_ci.
My html page has <meta charset="utf-8">

But when I echo $query[10]['scope'];
instead of getting (’) I get (�)

In phpMyAdmin when looking at the same data I see the proper quote character.
The phpmyadmin page is also specifying utf-8 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

What am I doing wrong?

This has been a pain in my side since I first started using php/mysql 7 years ago and I seem to be no closer to having a clue.
Warning: I have no idea what I'm talking about.
kon
Forum Newbie
Posts: 19
Joined: Sat Mar 03, 2012 5:43 am

Re: UTF 8 mysql problem with quote character

Post by kon »

Maybe this is not the case but to be sure add header in php file (before any output)

Code: Select all

<?php header('Content-Type: text/html; charset=utf-8'); ?>
Also save the file in UTF-8
as for html meta you could try ..
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Is this happening only for the single quote character? How do you output the string? Have tried to loop through letters of string and see their ASCII values (with ord) ?
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: UTF 8 mysql problem with quote character

Post by thinsoldier »

Turns out I needed to do this:

mysql_query('SET NAMES utf8;');
mysql_query('SET CHARACTER SET utf8;');
Warning: I have no idea what I'm talking about.
Post Reply