I have buffered page via ob_get_contents to $content variable. This content is loaded properly.
Now, from this string var I would like to extract all links related to images (accepting single and double quotes and format .png, .jpg, .jpeg., .gif, etc.) and check if these links have external path (http://server.com/path/). If true, save these files and replace external path to local (keep filename).
I tried simpliest way -> new DOCDocument - loadHTML($content), but I cant load DOM with proper (utf8) encoding (buffered string $content has proper charset, DOM no). I also tried html_entity, mb_encoding..., ->encoding('utf-8') etc. No effect.
$doc = new DOMDocument();
$doc->loadHTML($content);
$tags = $doc->getElementsByTagName('img');
foreach ($tags as $tag) { .... };
Then I tried regex way (preg_match_all, str_replace, etc.), but needed regex formula is too diffucult for me. Could you advice me which way is best and how to make it? Thank you.