|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-05-29 03:33 UTC] xiaobianmail at 126 dot com
Description:
------------
When the page encoding is gbk, this code will be fatal error.
>php -r 'var_dump("運");'
Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in Command line code on line 1
Test script:
---------------
>php -r 'var_dump("運");'
Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in Command line code on line 1
<?php
//126 GBK error
$count = $count2 = 0;
for($h = hexdec("8100"); $h <= hexdec("fe00"); $h = $h + 256){
$i=0;
for($l=hexdec("0040");$l<=hexdec("00fe");$l++){
$char16 = dechex($h+$l);
if(substr($char16,2,2) == '5c'){
echo pack("n*",$h+$l)."<br />";
$count2++;
}
$i++;
$count++;
}
}
echo $count;
echo"<br />";
echo $count2;
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 15:00:01 2026 UTC |
My solution : 1.str_replace("\\", " ", "XXXXXX"); 2.mb_substr("XXXXXX", 0, 1, "gbk");As you've seen, CP936 (which supports GBK) encodes 運 as ß\. This results in the characters var_dump("ß\") // 0xDF 0x5C and the unterminated string is what PHP is complaining about. Fun fact: that problem right there is why CP936 is one of the very few encodings that allows SQL injection via Unicode. CP936 just isn't safe. Use a different encoding in your console or find another way to represent that character (and the others like it) in code.