Selecting all the images of a URL using PHP

Hello to all,

I am using below code to select all the Image Source from a given URL.

<?php
$url_image = $_GET[‘url’];

$homepage = file_get_contents($url_image);

preg_match_all(“{<img\\s*(.?)src=('.?'|\”.?\"|[^\\s]+)(.?)\\s*/?>}ims", $homepage, $matches, PREG_SET_ORDER);

foreach ($matches as $val) {

echo “<img src='”.trim($val[2]).“’ width=‘50’ height=‘50’ >”;

}

?>

I have the following problems

  1. The Image SRC of some sites would be a complete url like “http://www.examplesite.com/images/super.jpg” and for some sites the URL, the image SRC may be “images/super.jpg” . how we can we get a standard SRC of the images in the HTML page

  2. In the above code I have displayed the selected image. But what happens is, The actual URL of the image added with the URL of the Current location where it is executed like “http://www.site.com/imageselector/http://www.examplesite.com/images/super.jpg” - How to overcome this issue.

Can you please help to resolve these two issues???

Thanks in Advance