#20934 [Ver]: htmlspecialchars returns latin1 from UTF-8

From: Date: Thu, 12 Dec 2002 13:19:14 +0000
Subject: #20934 [Ver]: htmlspecialchars returns latin1 from UTF-8
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-27473@lists.php.net to get a copy of this message
ID: 20934 Updated by: wez@php.net Reported By: renato@cria.org.br Status: Verified Bug Type: Strings related Operating System: Red hat linux 8.0 PHP Version: 4CVS-2002-12-11 (dev) New Comment: Is this problem also in the PHP 4.3.0RC3? If so, this should be resolved before release. Previous Comments: ------------------------------------------------------------------------ [2002-12-12 07:10:58] moriyoshi@php.net Thanks for your effort again. Verified this behaviour. ------------------------------------------------------------------------ [2002-12-11 06:58:14] renato@cria.org.br 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 this bug report at http://bugs.php.net/?id=20934&edit=1

« previous php.bugs (#27473) next »