DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Extracting Image With PHP

01.30.2012
| 2314 views |
  • submit to reddit
        //Extracting Image With PHP

$contenttograbimagefrom = $youroriginalhtmlwithimage;
$firstImage = "";
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $contenttograbimagefrom, $ContentImages);
$firstImage = $ContentImages[1] [0]; // To grab the first image
echo $firstImage;


credits: <b><a href='http://4dlink.com'>4DLink WebLists</a></b> and <a href='http://web4link.com'>web4link.com</a>