I want to get the URLs of all images of a given external page using PHP. Is this possible? And if so, how is it done?
Asked
Active
Viewed 1,922 times
3 Answers
0
Simplest way:
<?php
$mypage = file_get_contents('http://www.somepage.com/');
echo $mypage;
?>
Some times You should use curl functions
0
You could use something like this:
$directory = "http://somewebsite.tld/directory/to/images";
foreach($images as $image)
{
$relative_path = $directory.basename($image);
$r .= '<img src="'.$relative_path.'" />';
return $r;
}
This will generate a HTML list of all images in that directory.
Hope that helps

CustomNet
- 732
- 3
- 12
- 31
0
This may help you.
<?php
$page = file_get_contents($url);
preg_match_all('/<img src\="(?P<src>(.*)(?:jpe?g|png|gif))"(.*)>/',$page,$srcs);
print_r($srcs[1]);
$url
is the url of the page you want to get images from.
The regular expression gets images with extension jpg, jpeg, png and gif, you can add more extensions separated by |
.
In $srcs[1]
array you have all the urls of all the images.

Georgi
- 320
- 4
- 18