简体   繁体   English

如何检查RSS供稿是否正常工作?

[英]How do I check if a RSS feed is working?

For example, if there is an RSS feed and for some reason it is down or cannot be grabbed I want to display a simple message saying "feed cannot be grabbed". 例如,如果有RSS提要,但由于某种原因它已关闭或无法被抓取,我想显示一条简单的消息:“无法抓取提要”。

Right now PHP spits out a really ugly warning message. 现在,PHP发出了一个非常丑陋的警告消息。

note:I do not need to know whether it is valid. 注意:我不需要知道它是否有效。 I just need to know if the feed actually works. 我只需要知道提要是否真的有效。 I do not want to turn off warnings. 我不想关闭警告。 I want to spit out a simple echo if the feed is not working. 如果供稿不起作用,我想吐出一个简单的回声。 I am using PHP no libraries. 我正在使用PHP没有库。

Any thanks would be awesome! 谢谢,太棒了!

Rick 里克

You can manually handle any XML parsing errors by using the libxml_use_internal_errors function. 您可以使用libxml_use_internal_errors函数手动处理任何XML解析错误。

An example can be found here 可以在这里找到一个例子

You can do this: 你可以这样做:

error_reporting(E_WARNING);

if (!$xmlDoc->load($url)){ 

 echo ("Not content could be loaded.");

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM