|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44513 htmlspecialchars charset doesn't work
Submitted: 2008-03-23 20:14 UTC Modified: 2008-03-26 12:34 UTC
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: juan at multiporte dot com dot br Assigned: fb-req-jani (profile)
Status: Not a bug Package: Strings related
PHP Version: 5.2.5 OS: WinXP
Private report: No CVE-ID: None
 [2008-03-23 20:14 UTC] juan at multiporte dot com dot br
When using htmlspecialchars with charset UTF-8 in Windows, this not display anything if have special chars. But, if I use utf8_encode function, work nice.

I'm tested in Apache 2.0 and PHP 5.2.5.

Reproduce code:

var_dump(htmlspecialchars('mar?o', ENT_QUOTES, 'UTF-8'));


Expected result:
mar?o (in UTF-8)

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-25 13:25 UTC]
Works just fine for me using latest CVS snapshot. Try with this:

For Windows (zip):

For Windows (installer):

But I'd guess you're just not using it properly and you're not really passing valid UTF-8 data to it..
 [2008-03-25 22:32 UTC] juan at multiporte dot com dot br
Well, I tried using snap version and nothing... Let's go to tecnical infos:

PHP Code:
var_dump(htmlspecialchars('mar?o', ENT_QUOTES, 'UTF-8'));

string(0) ""
string(6) "mar?o"

PHP version: PHP Version 5.2.6RC3-dev 
PHP extensions: curl, gd2, gettext, mbstring, mcrypt, mysql, mysqli, openssl, pdo, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, soap, sockets, svn, xmlrpc, xsl
System: Windows NT ***** 5.1 build 2600 
Server API: Apache 2.0 Handler 
Apache version: Apache/2.0.59 (Win32) PHP/5.2.6RC3-dev SVN/1.4.4 DAV/2 
Apache modules: core mod_win32 mpm_winnt http_core mod_so mod_access mod_actions mod_alias mod_asis mod_auth mod_autoindex mod_cgi mod_dav mod_dir mod_env mod_imap mod_include mod_isapi mod_log_config mod_mime mod_negotiation mod_rewrite mod_setenvif mod_userdir mod_php5 mod_dav_svn mod_authz_svn 

iconv.input_encoding = ISO-8859-1
iconv.internal_encoding = UTF-8
iconv.output_encoding = UTF-8

Apache configuration (httpd.conf):
LoadModule php5_module "c:/arquiv~1/php5/php5apache2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php5

# configure the path to php.ini
PHPIniDir "C:/arquiv~1/php5"

More information about source file: The source code must be in ANSI mode for see that error. If the source file in UTF-8, work's great.
 [2008-03-26 11:52 UTC] you're passing non-utf8 to the function and use UTF-8 as charset and expect it to work? How is this a bug?
 [2008-03-26 12:34 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #43896

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jun 09 11:03:41 2023 UTC