FacebookYoutubeTwitterFlickr

Extract Image Source (Src) From HTML Content In PHP

This code will grab the first image source from an HTML content using preg_match_all  method in php and regular expression

$strFirstImage = "";

$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $strHTMLSourceContent, $ContentImages);

$strFirstImage = $ContentImages[1] [0]; // To grab the first image

echo $strFirstImage;

Comments:

20 Votes
0 Comments
Leave a Comment