PHP 从 URL 解析 XML [英] PHP parsing XML from URL
本文介绍了PHP 从 URL 解析 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码从 URL 获取一些 XML:
I'm using this code to get some XML from a URL:
$url = 'http://shelly.ksu.ru/e-ksu/get_schedulle_aud?p_id=563';
$xml = simplexml_load_file($url);
print_r($xml);
这给了我一个空的结果,但下面的链接给了我正确的结果:
This is giving me an empty result, but the following link gives me the correct results:
$url = 'http://habrahabr.ru/rss';
我似乎看不到这些链接之间的区别,也不知道如何在 Google 上找到答案.非常感谢任何帮助.
I can't seem to see the difference between these links and I don't know how to find the answer on Google. Any assistance is greatly appreciated.
推荐答案
这个 xml 文件字符集不是 UTF8 字符集,但是你可以看到这个 StdObject :
This xml file charset isn't UTF8 charset, but you can see the StdObject with this :
<?php
header('Content-type: text/html; charset=utf-8');
$url = 'http://shelly.ksu.ru/e-ksu/get_schedulle_aud?p_id=563';
$data = file_get_contents($url);
$data = iconv(mb_detect_encoding($data, mb_detect_order(), true), "UTF-8", $data);
$xml = simplexml_load_string($data);
print_r($xml);
这篇关于PHP 从 URL 解析 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文