Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试解析 rss 提要以仅显示图像。我正在使用通用的 wordpress 提要,并想去掉所有不是图像的东西。
我一直在玩simplepie,但还没有找到一种仅显示图像的可靠方法。
我找到了这个旧的 simplepie 论坛帖子 (http://simplepie.org/support/viewtopic.php?id=643) 但无法使代码正常工作。我想它现在可能已经过时了,但我不确定。
我不依赖于 simplepie,但确实需要在 php 中工作并输出 html。任何帮助将不胜感激!
或类似的东西:
$xml = simplexml_load_file($xml_file_path); $imgs = $xml->xpath('/rss/channel/image'); foreach($imgs as $image) { echo $image->url; }
查看SimpleXML。
使用它和xpath应该可以满足您的需求。
$feed = simplexml_load_file('foo.xml'); foreach ($feed->xpath('//img') as $imgnode) { // ... }