Getting special characters out of a MySQL database with PHP -
this question has answer here:
- utf-8 way through 14 answers
i have table includes special characters such ™.
this character can entered , viewed using phpmyadmin , other software, when use select statement in php output browser, diamond question mark in it.
the table type myisam. encoding utf-8 unicode. collation utf8_unicode_ci.
the first line of html head is
<meta http-equiv="content-type" content="text/html; charset=utf-8">
i tried using htmlentities() function on string before outputting it. no luck.
i tried adding php before output (no difference):
header('content-type: text/html; charset=utf-8');
lastly tried adding right below initial mysql connection (this resulted in additional odd characters being displayed):
$db_charset = mysql_set_charset('utf8',$db);
what have missed?
below code works me.
$sql = "select * chartest"; mysql_set_charset("utf8"); $rs = mysql_query($sql); header('content-type: text/html; charset=utf-8'); while ($row = mysql_fetch_array($rs)) { echo $row['name']; }
Comments
Post a Comment