GBK-encoded PHP script causes a syntax error (ZendMultibyte)

Source: Internet
Author: User
The following php code in GBK environment: "> <LINKhref =" http://www.php100.com//statics/style/headfloor_950_081205.css "type = text/cssrel = stylesheet> <LINKhref =" http://www.php100.com//st

 

The following php code in the GBK environment: Php syntax errors may occur. how can this problem be solved?

This is because, in the GBK environment, the encoding of "signature" is "0xab 0x5c, so it is a problem caused by '5c ..

In general, we recommend that you use unicode as the character set of the code file. if you want to use GBK, you can switch it.

However, if your script requires GBK encoding, how can this problem be avoided?

Beginning with PHP5.3, PHP introduced Zend Multibyte to support multi-character set encoding. the above code is modified as follows:

  

Declare (encoding = "cp936 ");

Echo ("Hong Ren Jing ");

?>

Then, configure in php. ini:

Mbstring. internal_encoding = cp936

Or run PHP with the following command:

$ Php-dmbstring. internal_encoding = cp936 test. php

In this way, PHP will execute test in the cp936 encoding mode. php. for more information about Zend Multibyte, see PHP: what is-enable-zend-multibyte configure option ?, PHP declare

PS. when I tested PHP5.4 RC1, I found a BUG. PHP 5.4 cannot correctly convert GBK encoding to UTF8 encoding, but now I have fixed it. if you encounter this problem, please pay attention to the PHP5.4 RC2 to be released soon .. thank you.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.