PHP加载远程XML出错???

请叫我小屁屁 2012-05-28 12:27:59
<?php
$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;

?>
<?php
//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<count($xml->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.'<br>';
}
?>
我在本地上可以获取到远程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
...全文
186 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
黄袍披身 2012-05-28
  • 打赏
  • 举报
回复
有部分字符可能乱码了,需要正确的编码
xuzuning 2012-05-28
  • 打赏
  • 举报
回复
$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版本和设置一样,可以省去不必要的麻烦
请叫我小屁屁 2012-05-28
  • 打赏
  • 举报
回复
怎么转啊?新手不会,xml是gb2312,网页是utf8[Quote=引用 3 楼 的回复:]

本地和服务器的编码不一样。
gb2312和utf-8转换一下试试。
[/Quote]
请叫我小屁屁 2012-05-28
  • 打赏
  • 举报
回复
怎么转啊?新手不会,xml是gb2312,网页是utf8[Quote=引用 3 楼 的回复:]

本地和服务器的编码不一样。
gb2312和utf-8转换一下试试。
[/Quote]
请叫我小屁屁 2012-05-28
  • 打赏
  • 举报
回复
怎么转啊?新手不会,xml是gb2312,网页是utf8[Quote=引用 3 楼 的回复:]

本地和服务器的编码不一样。
gb2312和utf-8转换一下试试。
[/Quote]
请叫我小屁屁 2012-05-28
  • 打赏
  • 举报
回复
貌似和编码没关系,我直接连接0百度mp3生成的xml才这样,如果我保存下来,放到另一个网站,再引用就没问题 了[Quote=引用 7 楼 的回复:]

$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版本和设置……
[/Quote]
qq120848369 2012-05-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

$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版本和设置……
[/Quote]

说的在理,刚才忙活了半天,空间和本地的php版本不兼容,好不容易排除了问题。
rex100 2012-05-28
  • 打赏
  • 举报
回复
本地和服务器的编码不一样。
gb2312和utf-8转换一下试试。
请叫我小屁屁 2012-05-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

有部分字符可能乱码了,需要正确的编码
[/Quote]应该怎么改??

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧