Find Nth Image in HTML
Using below function you can find Nth Image in your HTML Code
function getImageInHTML($post, $default, $i = 0)
{
preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post, $matches);
if( isset($matches[1][$i]) && !empty( $matches[1][$i] )){return $matches[1][$i];}
if(isset($matches[1][0]) && !empty( $matches[1][0] )){return $matches[1][0];}
return $default;
}
No Comments
Leave a comment Cancel