Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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解析-我只能找到文件类型吗?_Php_Html_Simple Html Dom - Fatal编程技术网

Php html dom解析-我只能找到文件类型吗?

Php html dom解析-我只能找到文件类型吗?,php,html,simple-html-dom,Php,Html,Simple Html Dom,在解析页面内容时,我只想列出图像,但更愿意按文件扩展名查找它们,因为我可能只需要jpg而不需要png 我知道我可以这样做来列出src标记中的所有图像,但我只想要上面详述的图像: foreach($html->find('img') as $e) 我读过在线文档,但没有提到如何/如果可以做到这一点 更新 这是我目前使用的代码: include('simple_html_dom.php'); function getUrlAddress() { /*** check for https i

在解析页面内容时,我只想列出图像,但更愿意按文件扩展名查找它们,因为我可能只需要jpg而不需要png

我知道我可以这样做来列出src标记中的所有图像,但我只想要上面详述的图像:

foreach($html->find('img') as $e)
我读过在线文档,但没有提到如何/如果可以做到这一点

更新

这是我目前使用的代码:

include('simple_html_dom.php');

function getUrlAddress()
{
/*** check for https is on or not ***/
$url = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
/*** return the full address ***/
return $url .'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}

$html = file_get_html($url);

foreach($html->find('img') as $e) // here I want to find just e.g. .jpg OR .png files instead of <img>

echo '<img src='.$e->src .'><br>';
include('simple_html_dom.php');
函数getUrlAddress()
{
/***检查https是否打开***/
$url=$\服务器['HTTPS']=='on'?'HTTPS':'http';
/***返回完整地址***/
返回$url.'://'.$服务器['HTTP\U主机].$服务器['REQUEST\U URI'];
}
$html=file\u get\u html($url);
foreach($html->find('img')as$e)//这里我只想查找例如.jpg或.png文件,而不是src。>
这应该可以:

$jpgs = $html->find('img[src$=jpg]'); 

请添加更多信息。页面或图像来自何处?可以使用此XPath:
//img[contains(@src,.jpg')]
我们还需要背景中的所有图像,如背景图像:url();或背景:url();。