Question

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>';
Was it helpful?

Solution

This should work:

$jpgs = $html->find('img[src$=jpg]'); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top