Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP简单HTML DOM解析器从RSS提要解析img_Html_Image_Parsing_Dom - Fatal编程技术网

使用PHP简单HTML DOM解析器从RSS提要解析img

使用PHP简单HTML DOM解析器从RSS提要解析img,html,image,parsing,dom,Html,Image,Parsing,Dom,我正在尝试解析此站点(以获取img链接): 这是我的代码: include 'parse/simple_html_dom.php'; // Create DOM from URL or file $html = file_get_html('http://statigr.am/feed/parishilton/'); // Find all images foreach($html->find('img') as $element) { echo $element->

我正在尝试解析此站点(以获取img链接):

这是我的代码:

include 'parse/simple_html_dom.php';

// Create DOM from URL or file
$html = file_get_html('http://statigr.am/feed/parishilton/');

// Find all images
foreach($html->find('img') as $element)
{
       echo $element->src . '<br>';
}      
包括“parse/simple_html_dom.php”;
//从URL或文件创建DOM
$html=file\u get\u html('http://statigr.am/feed/parishilton/');
//查找所有图像
foreach($html->find('img')作为$element)
{
echo$element->src.“
”; }

脚本没有返回任何内容!为什么呢?我想要
img
链接。

这是因为所有图像都在
CDATA
部分中,解析器会忽略它,所以解决方案是

$html = file_get_html('http://statigr.am/feed/parishilton/');
$html = str_replace("<![CDATA[","",$html); // clean-up
$html = str_replace("]]>","",$html); // clean-up
$html = str_get_html($html); // re-construct the dom object
// Loop
foreach($html->find('item description img') as $el)
{
    echo $el->src . "<br />";
}

谢谢如果我想要链接、描述和发布时间在同一个数组中,我该怎么做?产出:1。链接:bla描述:xx时间:xx 2。链接描述:xx时间:xx
foreach($html->find('item')as$el){echo$el->find('description img',0)->src.
“echo$el->find('link',0)->innertext.
;“echo$el->find('pubDate',0)->innertext。
http://distilleryimage3.s3.amazonaws.com/cc25d8562c9611e3a8b922000a1f8ac2_8.jpg
http://distilleryimage7.s3.amazonaws.com/4d8e22da2c8911e3a6a022000ae81e78_8.jpg
http://distilleryimage5.s3.amazonaws.com/ce6aa38a2be711e391ae22000ae9112d_8.jpg
http://distilleryimage3.s3.amazonaws.com/d64ab4c42bc811e39cbd22000a1fafdb_8.jpg
......
......