Xajax Library Chinese problems and prompts in PHP returns an invalid solution to an XML file

Source: Internet
Author: User
Tags character set php class php and php code xml parser smarty template

Xajax is a very good AJAX framework for PHP, although Xajax says that he is a library, but I think it's more like a framework (framework). Xajax is an open-source PHP class library that allows you to glue HTML, CSS, JavaScript, and PHP, and can be used in conjunction with Smarty template systems.

When using the Xoops page module, it was found that it could not work with Chinese, especially pages that could not be encoded with UTF-8, and yesterday, when using the DataGrid to realize that it was completely out of work, "The XML response" was Returned from the ' Server is invalid ' This error, Google a bit, and found that a lot of people have this problem. Combining the previous solution to the Xoops page module (thanks to the civilized pig) UTF-8 use of the problem, finally found the perfect solution to the Xajax library to use Chinese method.

If the page uses GB2312 or GBK as the encoding or character set, the method mentioned above in the general network can be resolved: Attention should be paid to common.php, PHP files used by server.php and server.php (especially those that generate data) are not saved using the UTF-8 encoding format and are saved in ASCII format. At the same time server.php output of the data content is best to use gb2312 coding.

Defined earlier in common.php

PHP code

Define (' xajax_default_char_encoding ', ' GB2312 ');

And then used at the time of the call:

PHP code

$xajax = new Xajax ();

$xajax->decodeutf8inputon ();

Or

PHP code

$xajax = new Xajax (' gb2312 ');

$xajax->setcharencoding ();

$xajax->decodeutf8inputon ();

$objResponse = new Xajaxresponse (' gb2312 ');

If the page uses the UTF-8 character set, some people on the internet say that using the UTF-8 format is OK, in fact, even if all the use of UTF-8 encoding does not work properly, or will complain: "The XML response that is returned from the Server is invalid ". Lenovo to the previous encounter in IE UTF-8 BOM Bug (article: IE under the page without a single line and UTF8 page can not show the solution), will this local server back to the XML file also contains a number of UTF-8 BOM content? The ethereal intercepts the packets to discover that the content that the server returns also really contains many UTF-8 BOM, possibly also is the Microsoft XML parser of IE uses the UTF-8 BOM bug. This solution is out: all the pages using UTF8 encoding and using no UTF-8 BOM Save (UltraEdit operation method: F12 or Save as the interface format dropdown box select ' utf-8-no BOM '), the page includes Xajax library files, common.php files , server.php files. Pages for access can also be saved using a no UTF-8 BOM.

Sometimes the returned parameters (especially the Chinese part) are encoded by the URL, which requires us to process the returned data using UrlDecode so that the following database operations can be completed normally.

Latest Xajax 0.25 Download address: Http://prdownloads.sourceforge.net/xajax/xajax_0.2.5.zip?download

Xajax Chinese Manual (Honestqiao first Edition, Flyinghail modified edition) http://www.flyinghail.net/?p=44

UTF-8 BOM Explanation: "EF BB BF" This three bytes is called Bom,bom's full name is called "byte order Mard". In the UTF-8 file commonly used BOM to indicate that this file is a UTF-8 file, and the original meaning of the BOM is UTF-16 to represent the high and low byte sequence.

In addition, the PHP site said that using--enable-zend-multibyte can solve such problems, but did not try, and is expected in PHP 6.0 will be the perfect support for Unicode.

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.