The problem of empty output of htmlspecialchars after php5.4 has been upgraded from the old version to php5.4. I am afraid the most troublesome problem is the problem of htmlspecialchars! Of course, htmlentities will also be affected. However, htmlspecialchars is common for Chinese websites and htmlentities are rarely used.
Foreigners may think that web pages are generally UTF-8 encoded, so they suffer from Chinese websites that use GB2312 and GBK encoding ......!
Specific performance:
$ Str = "9enjoy.com's php version is 5.2.10 ";
Echo htmlspecialchars ($ str );
The output in the gbk character set is null... UTF-8, and the output is normal.
Why? the reason is the change to this function in 5.4.0:
5.4.0 The default value for the encoding parameter was changed to UTF-8.
Defines encoding used in conversion. If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards.
The original is ISO-8859-1, 5.4 after the default into UTF-8! Then use this function in Chinese and the output is blank.
A bunch of open-source programs in China will have such problems in 5.4. DISCUZ officially recommends that users do not upgrade to 5.4.
Solution:
1. modify all programs that use htmlspecialchars.
1.1 The second $ flags parameter. the default value is ENT_COMPAT.
Htmlspecialchars ($ str, ENT_COMPAT, 'gb2312 ');
Why not GBK? If the GBK parameter is not specified, an error is returned if the GBK parameter is forcibly used:
Warning: htmlspecialchars (): charset 'gbk' not supported, assuming UTF-8
Change:
Htmlspecialchars ($ str, ENT_COMPAT, 'ISO-8859-1 ');
1. 2. change the program, but you can omit a parameter.
You can add
Ini_set ('default _ charset', 'gbk ');
Then change
Htmlspecialchars ($ str, ENT_COMPAT ,'');
The file contains: An empty string activates detection from script encoding (Zend multibyte), default_charset and current locale (see nl_langinfo () and setlocale (), in this order. Not recommended.
It indicates that the default_charset encoding is used when an empty string is passed in.
1. 3. encapsulate a function... the word htmlspecialchars has never been easy to remember.
Function htmlout ($ str ){
Return htmlspecialchars ($ str, ENT_COMPAT, 'ISO-8859-1 ');
}
Then replace them in batches.
2. directly modify the source code and re-compile it! This is also my current online solution.
Modify ext/standard/html. c
About 372 rows
/* Default is now UTF-8 */
If (charset_hint = NULL)
Return cs_utf_8;
Change cs_utf_8 to cs_8859_1.
/* Default is now UTF-8 */
If (charset_hint = NULL)
Return cs_8859_1;
After compilation, the original program does not need to be adjusted.
For installation method, see: http://www.9enjoy.com/linux-upgrade-php54/
What should I do in windows? Here, you can find a way to compile it, which is difficult...
Provide a URL for reference: http://www.phpvim.net/web/php/build-php5-4-and-xdebug-on-win32.html
Let's quote one sentence: preparing coffee and cola may take several hours to prepare...
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.