From: [EMAIL PROTECTED]
Operating system: Red hat linux 8.0
PHP version: 4CVS-2002-12-11 (dev)
PHP Bug Type: Strings related
Bug description: htmlspecialchars returns latin1 from UTF-8
I used the script bellow for testing (calling it from MS Internet Explorer
to directly see the xml output).
Calling it without parameters one should see a simple xml document showing
a string in latin1.
Calling it with "?charset=utf8", the script correctly converts the string
from latin1 to UTF-8 but after using "htmlspecialchars" it goes back to
latin1, and the xml becomes invalid. (put a comment on the
"htmlspecialchars" line after the character conversion and the xml will
show up in UTF-8 without problem).
<?php
$string = "Hello from S�o Paulo";
$charset = isset($_GET["charset"]) ? $_GET["charset"] : "latin1";
if ($charset == "utf8")
{
$charset_code = "UTF-8";
$show_string = mb_convert_encoding($string, "UTF-8", "ISO-8859-1");
$show_string = htmlspecialchars($show_string, ENT_COMPAT, "UTF-8");
}
else
{
$charset_code = "ISO-8859-1";
$show_string = htmlspecialchars($string);
}
header ("Content-type: text/xml");
echo "<?xml version='1.0' encoding='$charset_code' ?>\n";
?>
<test>
<?php print($show_string); ?>
</test>
--
Edit bug report at http://bugs.php.net/?id=20934&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=20934&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=20934&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=20934&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=20934&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=20934&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=20934&r=support
Expected behavior: http://bugs.php.net/fix.php?id=20934&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=20934&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=20934&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=20934&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20934&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=20934&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=20934&r=isapi