alamb Posted October 1, 2010 Share Posted October 1, 2010 Hello, I am very confused as to why when I try to change my charset="UTF-8" from "ISO-8859-1" I now get box characters displayed where I used to have curly quotes and dashes in the text coming out of a MySQL database. I had originally used the default db varchar setting "latin1_swedish_ci" and have since changed that to be "utf8_unicode_ci" for this particular 'text' field. I have stripped my code down to the following for your consideration. The output from this is where the ? marks appear as boxes in my browser: Real Case � It�s I should look this and does when I change back to charset="ISO-8859-1": Real Case – It’s Here is my PHP code. Thanks in advance for your help. <?php // session start must happen before any other output session_start(); // debug only ini_set('display_errors',1); //ISO-8859-1 header("Content-type: text/html; charset=UTF-8"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test</title> </head> <?php ## secret password file ## include("tempars.inc"); // globals $query = ""; $qtext = ""; $mID = "abc 123"; $qID = "7"; // global connection ($cxn) to get current question ($qID) $cxn = mysql_pconnect($host,$user,$password); mysql_select_db($dbname); $query = "SELECT * FROM question WHERE mID='$mID' AND qID='$qID'"; $result = mysql_query($query); if($result == false) { echo "<h4>SELECT Error: ".mysql_error($cxn)."</h4>"; } elseif(@mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); $qtext = $row['text']; } echo "<body >"; echo "$qtext"; mysql_close($cxn); echo "</body></html>"; // end of the program ?> Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted October 1, 2010 Share Posted October 1, 2010 Try utf8_encode function http://php.net/manual/en/function.utf8-encode.php on the text coming from the mysql database. Quote Link to comment Share on other sites More sharing options...
alamb Posted October 1, 2010 Author Share Posted October 1, 2010 No, that did not fix it but it did change the boxes into spaces. Output now: Real Case Its I changed: $qtext = $row['text']; to be: $qtext = utf8_encode($row['text']); Quote Link to comment Share on other sites More sharing options...
alamb Posted October 2, 2010 Author Share Posted October 2, 2010 Sorry, that output above was not right - I would have been happy with that. I must have fat fingered the copy/paste. The output now is: Real Case It s Quote Link to comment Share on other sites More sharing options...
alamb Posted October 2, 2010 Author Share Posted October 2, 2010 Follow-up... I'm guessing at this point that it must have something to do with how the data has been encoded in the database. Even though I have changed the db 'collation' field to be unicode, there must be something else that is necessary when I "INSERT" the data. I have also added a "SET NAMES utf8" after connection, but that doesn't seem to fix it either. Anyone know what I'm missing here? Any other ideas? Quote Link to comment Share on other sites More sharing options...
jskywalker Posted October 2, 2010 Share Posted October 2, 2010 try changing default charset, in stead of default collation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.