PHP头条
热点:

PHP加载远道XML出错?


PHP加载远程XML出错???
$yinyue=$_GET['yinyue'].'$$';
if ($_GET['geshou']=="") {
$a="";}
else{
$a="$$$$";}
$geshou=$_GET['geshou'].$a;
$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 ; $iurl) ; $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.'
';
}
?>
我在本地上可以获取到远程xml中我想要的数据,但是我上传到服务器空间就出现错误了???为什么啊

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


------解决方案--------------------
有部分字符可能乱码了,需要正确的编码
------解决方案--------------------
本地和服务器的编码不一样。
gb2312和utf-8转换一下试试。
------解决方案--------------------
$s = str_replace('encoding="gb2312"', 'encoding="utf-8"', file_get_contents($file));
$xml = simplexml_load_string($s) or die ("Unable to load XML file!");

你服务器上的 php 版本偏低了
在本地调试时最好与服务器上的php版本和设置一样,可以省去不必要的麻烦
------解决方案--------------------
探讨

$s = str_replace('encoding="gb2312"', 'encoding="utf-8"', file_get_contents($file));
$xml = simplexml_load_string($s) or die ("Unable to load XML file!");

你服务器上的 php 版本偏低了
在本地调试时最好与服务器上的php版本和设置……

www.phpzy.comtrue/phprm/38339.htmlTechArticlePHP加载远道XML出错? PHP加载远程XML出错??? $yinyue=$_GET['yinyue'].'$$'; if ($_GET['geshou']=="") { $a="";} else{ $a="$$$$";} $geshou=$_GET['geshou'].$a; $music='http://box.zhangmen.baidu.com/x?op=12title='.$yinyue.$gesho...

相关文章

PHP之友评论

今天推荐