Currently, I’m using Simple HTML DOM which works great for tags:
$html = file_get_html($url);
$images = $html->find('img');
$result = '';
foreach ($images as $image):
$result .= '<img src="'.$this->tasks->rel2abs($image->src, $url).'"><br>';
endforeach;
$html->clear();
unset($html);
echo $result;
But how would I also get images from CSS files, such as background: or background-image:?
I assume you’re using PHP Simple HTML DOM Parser. The following code is untested, but it should be pretty close to what you need.
First, you’ll need to get all of the CSS blocks by using a search similar to yours above.
…then you can search the inline blocks for
url():…then fetch the external css files and repeat:
$css_imagesshould then be filled with image urls. It’s a good idea to runarray_uniqueto eliminate dupes, and you may have to prepend path information if they use relative paths.Again, this is untested from memory, but it should get you close. This will not find any images that are inserted via Javascript. That would be a much trickier proposition.