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
?>