php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61862 mb_convert+htmlspecialchars returns nothing.
Submitted: 2012-04-27 02:32 UTC Modified: 2012-04-27 02:48 UTC
From: jeniffer at tormail dot net Assigned:
Status: Not a bug Package: mbstring related
PHP Version: 5.4.1 OS: Windows
Private report: No CVE-ID: None
 [2012-04-27 02:32 UTC] jeniffer at tormail dot net
Description:
------------
In PHP 5.3.x, I can get expect result.
But in PHP 5.4.x, this returns nothing. Why?

Test script:
---------------
<?php
$converttext="こんにちは世界";
$converttext=mb_convert_encoding($converttext,"SJIS","auto");
$converttext=htmlspecialchars($converttext,ENT_QUOTES);
echo $converttext;
?>

Expected result:
----------------
こんにちは世界 (in SJIS)

Actual result:
--------------
(nothing)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-27 02:48 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-04-27 02:48 UTC] rasmus@php.net
This was actually a bug in 5.3. 5.3, unless you specified differently would just 
assume iso-8859-1 and since every single-byte sequence is a valid char in 8859-
1, as long as it didn't see any bytes matching any special html chars, it would 
pass them right through in this case. So it wasn't actually escaping anything 
unless you got lucky and your charset was compatible with 8859-1 for those 
chars. 

This function now assumes UTF-8 if you don't specify differently and if it sees 
something that isn't UTF-8 it returns nothing. Since this is a security-related 
function, we can't just pass things through we don't understand. So in your case 
you want to pass 'SJIS' as the 3rd arg to htmlspecialchars() there, or you can 
pass '' and it will use the script encoding in zend_multibyte mode.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 03 02:05:54 2022 UTC