-3

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?

Pixark
  • 385
  • 1
  • 4
  • 13

3 Answers3

0

Simplest way:

<?php
    $mypage = file_get_contents('http://www.somepage.com/');
    echo $mypage;
?>

Some times You should use curl functions

Please look at this answear!

Community
  • 1
  • 1
Adam
  • 1,371
  • 2
  • 11
  • 12
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