我有一个网站"mysite.com",这有一个位于mysite.com/feed的rss/xml提要。
我必须在php脚本中阅读此提要,但simplexml_load_file
返回空结果。我如何获得"真实"的feed路径?我假设这个文件是用一些聪明的。htaccess之类的东西创建的。
我认为这与。htaccess无关。要获取提要,您有两种选择。一个用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。更多细节请点击