Ins*_*dJW 6 php validation rss simplepie
我决定使用SimplePie来解析RSS和Atom Feeds.
我想做的是让人们通过文本字段输入RSS和Atom Feeds URL.
如果他们放置无效的RSS和Atom Feeds怎么办?
我知道无法通过SimplePie解析无效的Feeds.
但是我想知道Feeds是否能够通过SimplePie解析.
通过该过程,我想删除那些无效的RSS提要URL列表.
检查文档类型,XML或HTML将是查找有效性的第一步.
我怎么能用PHP做到这一点?还是有其他方法可以做我想做的事情?
要检查Simplepie是否能够解析Feed,您只需加载有问题的Feed并检查错误:
$feed = new SimplePie();
$feed->set_feed_url('http://example.com/rss');
$feed->init();
$feed->handle_content_type();
if ($feed->error())
{
// this feed has errors
}
Run Code Online (Sandbox Code Playgroud)
您可能希望禁用自动发现功能以测试特定的Feed网址.此外,您可以自己查询Feed数据,set_raw_data而不是使用set_feed_url.