I need some help, geting all the images in my article.
At the moment to get only the first image i use this :
$first_img = '';
$mycontent = $row['post_content'];
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $my1content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/img/default.png";}
This get only the first image from the article..
So what i need it , to get all the images from the article, and show them in a row.
Thank you
The
preg_match_allfunction will return an array matches,foreachloop would be sufficient.http://php.net/manual/en/function.preg-match-all.php
Better pattern:
/<img(?:(?!src).)+src="?([^"\']+)/iTo handle the multiple matches you can do the following: