I have been trying to get the HTML of an external website and look through it with PHP. I want to show images from the site, so I tried changing img sources from /assets/img/example.png
to www.example.com/assets/img/example.png
by getting the current src attribute like so (after getting each image from the document):
$current_src = $img->getAttribute("src");
and then assigning the current_src
to the image along with the main URL. But this puts the new image in <noscript>
tags like this:
<img data-cfsrc="http://www.example.com"><noscript><img src="/assets/img/example.png></noscript>
EDIT: A simple example of what I am doing is here (just for the first image):
$test_img = $doc->getElementsByTagName('img')[1];
$test_img->setAttribute("src", "http://www.example.com" . $test_img->getAttribute("src"));
echo $test_img->getAttribute("src");
And this echoes http://www.example.com/assets/img/logo-bar.png
, but when I go back to the view source I see that it is in a seperate tag like this:
<img style="display:none;visibility:hidden;" data-cfsrc="/assets/img/logo-bar.png" alt="example Logo"><noscript><img src="http://www.example.com/assets/img/logo-bar.png" alt="example Logo"></noscript>
What causes this? And how can I prevent this from happening?