php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62516 Impossible to display Unicode names
Submitted: 2012-07-09 13:06 UTC Modified: 2012-07-09 16:03 UTC
From: pl at mygrworld dot com Assigned:
Status: Not a bug Package: mbstring related
PHP Version: 5.3.14 OS: Linux
Private report: No CVE-ID: None
 [2012-07-09 13:06 UTC] pl at mygrworld dot com
Description:
------------
---
From manual page: http://www.php.net/function.print
---
A BOM mark is present at the top of the PHP script, the locale is set to UTF-8, 
as is the HTML Content Type. In Apache, the charset is also set to utf8.

When Unicode characters are requested from MySQL, neither the echo or print 
functions display the characters correctly within the HTML code. However, if the 
characters are written directly in the HTML, they are displayed correctly.

Data is requested from the MySQL database using mysql_query and 
mysql_fetch_assoc (or_array) into a variable (e.g. $var). A variable dump is 
made of the data retrieved from the database, which shows the required data in 
the format wanted. 

However, using "<?php echo $var[0]; ?>", "<?php print $var[0]; ?>" or "<?
=$var[0];?>" does not get the required result in the middle of the HTML code.

Test script:
---------------
<?php
setlocale(LC_ALL,"se_NO.utf8");
$query = "SELECT town, state FROM data_table WHERE town_id = 1";
$result=mysql_query($query, $sql_id);
$town=mysql_fetch_assoc($result));
?>
<!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" />
</head>
<body>
<?=$town['town'];?><br>
<? echo $town['state'];?>
</body>
</html>

Expected result:
----------------
Borås
Västra Götaland

Actual result:
--------------
Bor�s
V�stra G�taland

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-09 13:52 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-07-09 13:52 UTC] rasmus@php.net
PHP doesn't do anything to the bytes that come out of MySQL here. It is a 
straight binary-safe pass through so the problem can't be in PHP. I suspect you 
haven't set the encoding on your MySQL table correctly. See 
http://dev.mysql.com/doc/refman/5.5/en/charset-database.html and in the user 
comments at the bottom it shows you how to check the current encoding.
 [2012-07-09 15:49 UTC] pl at mygrworld dot com
I checked that and actually dumped the variable value after it had been collected 
from the database. It was in the correct format. There has to have been a change 
between it being read from the database and written to disk, before it was then 
included in the HTML for display.
 [2012-07-09 16:03 UTC] rasmus@php.net
Like I said, PHP doesn't touch it. Whatever comes back from MySQL is what will 
end up in your PHP variable.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 11:01:27 2024 UTC