我有一个网站“mysite.com”,它有一个位于mysite.com/feed的rss / xml-feed。
我必须在php脚本中阅读此Feed,但simplexml_load_file
返回空结果。如何获得Feed的“真实”路径?我假设这个文件是使用一些聪明的.htaccess等创建的。
答案 0 :(得分:1)
我认为它与.htaccess无关。要获得Feed,您有两种选择。
一个使用file_get_content
,另一个使用cURL
。
$xml = file_get_contents('http://mysite.com/feed');
和
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://mysite.com/feed');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
现在$xml
持有xml文件,因此您可以使用simplexml_load_file
来解析它。
另一种方法是你可以使用Rss PHP。更多详情为here