Jump to content

UTF-8 charset is replacing special chars with boxes?? Please help!


alamb

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.