php5.4 above version GBK encoding htmlspecialchars output is empty problem resolution summary, Htmlspecialchars
Upgrade from the old version to php5.4, I am afraid the most troublesome is htmlspecialchars this problem! Of course, Htmlentities will also be affected, however, for the Chinese station generally used htmlspecialchars more common, htmlentities very little use.
Perhaps the foreigner thinks that the webpage generally should be the Utf-8 code, therefore bitter those uses the GB2312,GBK code the Chinese station ...!
Specific performance:
Copy the Code code as follows:
$STR = "PHP version of 9enjoy.com is 5.2.10";
echo Htmlspecialchars ($STR);
GBK Character Set output is empty ... utf-8, output is normal.
Why, the reason is the change of 5.4.0 to this function:
Copy the Code code as follows:
5.4.0 the default value for the encoding parameter is changed to UTF-8.
What was it?
Copy the Code code as follows:
String Htmlspecialchars (string $string [, int $flags = Ent_compat | ent_html401 [, String $encoding = ' UTF-8 ' [, bool $double _encode = true]])
Defines encoding used in conversion. If omitted, the default value for this argument are iso-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 Onwards.
Turns out to be utf-8! after iso-8859-1,5.4. Then the Chinese use this function to output as blank.
A bunch of open-source programs in China in 5.4 will have such a problem, DISCUZ officials also recommend that users do not upgrade to 5.4
Solution:
1. Painful modification of all procedures used in htmlspecialchars places
1.1 Its second $flags parameter, default is Ent_compat, so change to
copy code code as follows:
Htmlspecialchars ($str, Ent_compat, ' GB2312 ');
Why not GBK? Because there is no GBK this parameter, if you force the use of GBK, then the error to show you:
Copy Code code is as follows:
Warning:htmlspecialchars (): CharSet ' GBK ' not Supported, assuming Utf-8
to be able to use GBK, change to:
Copy code code as follows:
Htmlspecialchars ($str, Ent_ COMPAT, ' iso-8859-1 ');
1.2. The same procedure is changed, but one parameter can be omitted.
You can add
to the header of the page to copy the code code as follows:
Ini_set (' Default_charset ', ' GBK ');
then change to
to copy the code code as follows:
Htmlspecialchars ($str, Ent_compat, ");
The
is written in the document: an empty string activates detection from script encoding (Zend multibyte), Default_charset and current locale (s EE nl_langinfo () and setlocale ()), in this order. Not recommended.
probably means: passing in an empty string uses the encoding of Default_charset
1.3. Encapsulate a function ... Originally htmlspecialchars This word has been difficult to remember.
Copy the Code code as follows:
function Htmlout ($STR) {
Return Htmlspecialchars ($str, Ent_compat, ' iso-8859-1 ');
}
Then go to bulk replace.
2. Directly modify the source code, re-compile! That's what I'm doing online right now.
Modify EXT/STANDARD/HTML.C
It's about 372.
Copy the Code code as follows:
/* Default is now UTF-8 */
if (Charset_hint = = NULL)
return cs_utf_8;
Change the cs_utf_8 into a cs_8859_1.
Copy the Code code as follows:
/* Default is now UTF-8 */
if (Charset_hint = = NULL)
return cs_8859_1;
After compiling, the original program will not have to make any adjustments.
Installation method can refer to: http://www.bkjia.com/article/63388.htm
What to do under Windows? This, I think of ways to compile it, the difficulty is larger ...
Provide a Web site for reference: http://www.bkjia.com/article/63391.htm
Quote a sentence: Get ready for coffee, Coke, get ready, you may have to toss for hours ...
http://www.bkjia.com/PHPjc/978728.html www.bkjia.com true http://www.bkjia.com/PHPjc/978728.html techarticle php5.4 above version GBK encoding htmlspecialchars output is empty problem resolution summary, htmlspecialchars from the old version upgrade to php5.4, I am afraid the most troublesome is htmlspecialchars this problem ...