Author Topic: [SOLVED] Extract image from URL  (Read 221 times)

0 Members and 1 Guest are viewing this topic.

Offline swampTopic starter

  • Enthusiast
  • Posts: 87
    • View Profile
[SOLVED] Extract image from URL
« on: July 02, 2009, 09:25:17 AM »
Hi there,

Could anyone give me a hand with this? I need to extract an image from a remote URL (Just the first image on the site)..

so if $url = 'http://www.bbc.co.uk' it would grab the first image it finds on the site.

Cheers

Offline Adam

  • Guru
  • Fanatic
  • *
  • Posts: 4,702
  • Gender: Male
    • View Profile
Re: Extract image from URL
« Reply #1 on: July 02, 2009, 09:32:46 AM »
You can use file_get_contents() to get the source code, then use preg_match() to locate the first image. The pattern would be something like:

Code: [Select]
<img[^\bsrc\b]+src="(.+?)"[^>]+>
Ronnie Wood, true or false?