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

  • 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=''>4DLink WebLists</a></b> and <a href=''></a>