PHP載入遠道XML出錯?
最後更新:2016-06-13
來源:互聯網
上載者:User
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版本和設定……