An error occurred while loading the remote XML in PHP?

Source: Internet
Author: User
An error occurred while loading remote XML in PHP ??? & Lt ;? Php $ yinyue = $ _ GET ['Y']. '$'; if ($ _ GET ['geshou'] ==& quot; & quot;) {$ a = & quot ;;} else {$ a = & quot; $ & quot; ;}$ geshou = PHP remote XML loading error ???
$ Yinyue = $ _ GET ['Y']. '$ ';
If ($ _ GET ['geshou'] = ""){
$ A = "";}
Else {
$ A = "$ ";}
$ Geshou = $ _ GET ['geshou']. $;
$ Music = 'http: // box.zhangmen.baidu.com/x? Op = 12 & count = 1 & title = '. $ yinyue. $ geshou;

?>
// Set name of XML file
$ File = "$ music ";
// Load file
$ Xml = simplexml_load_file ($ file) or die ("Unable to load XML file! ");
For ($ I = 0; $ I Url); $ I ++)
{
$ A = $ xml-> url [$ I]-> encode;
$ B = $ xml-> url [$ I]-> decode;
$ C = substr ($ a, 0, strrpos ($ a, '/') + 1 );
$ Result = trim ($ c). trim ($ B );
Echo $ result .'
';
}
?>
I can obtain the data I want from remote xml locally, but an error occurs when I upload the data to the server space ??? Why?

Warning: simplexml_load_file () [function. simplexml-load-file]: http://box.zhangmen.baidu.com/x? Op = 12 & count = 1 & title = % E9 % 85% B7 % E7 % 88% B1 % 24% 24: 1: parser error: switching encoding: encoder error in/home/xintutuc/public_html/y/music. php on line 22


------ Solution --------------------
Some characters may be garbled and must be correctly encoded.
------ Solution --------------------
The local and server encoding is different.
Convert gb2312 and UTF-8.
------ Solution --------------------
$ S = str_replace ('Encoding = "gb2312" ', 'Encoding = "UTF-8"', file_get_contents ($ file ));
$ Xml = simplexml_load_string ($ s) or die ("Unable to load XML file! ");

The php version on your server is low.
It is best to use the same php version and settings on the server during local debugging to save unnecessary trouble.
------ Solution --------------------
Discussion

$ S = str_replace ('Encoding = "gb2312" ', 'Encoding = "UTF-8"', file_get_contents ($ file ));
$ Xml = simplexml_load_string ($ s) or die ("Unable to load XML file! ");

The php version on your server is low.
It is best to use the php version and settings on the server during local debugging ......

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.