html dom parse - can i find only file types?
-
12-11-2019 - |
質問
While parsing the contents of a page I want to just list images, but, would rather find them by file extension as I might only want jpg and not png for example.
I know I can do this to list all images from within src tags but I want just the image as detailed above:
foreach($html->find('img') as $e)
I have read online docs but can find no mention of how/if that can be done?
UPDATE
This is the code i currently use:
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>';
解決
This should work:
$jpgs = $html->find('img[src$=jpg]');
所属していません StackOverflow