i am trying to achieve this. I have alot of HTMLs that looks somethinglike this (for example).
<div>
<img src="http://firstsite.com/path/to/img/main.jpg" style="width: 500px; height: 400px;" />
</div>
Now i try to make a php that automatically changes the path of the images to another website, but i also want to download the images and put them into same folder structure. So far i did this:
$input = "c:/wamp/www/primo/input12";
$output = "c:/wamp/www/primo/output12";
$handle = opendir($input);
while (($file = readdir($handle)) !== false) {
if($file != '.' && $file != '..') {
$data = file_get_contents($input . "/" . $file);
$data = str_replace("http://firstsite.com/", "http://secondsite.com", $data);
file_put_contents($output . "/" . $file, $data);
}
}
closedir($handle);
This changes the path but now i need to somehow get into a variable the full path http://firstsite.com/path/to/img/main.jpg
in my example in order to download the image.
Is there a way to get the full path of the images while replacing http://firstsite.com/
which is just the begining of the path ?
Thank you in advance, Daniel!