tags:

views:

76

answers:

3
function has_thumbnail_image(&$post) {
 $content = $post->post_content;
 return preg_match('/<img[^>]+src="(.*?)"[^>]*>/', $content, $results);
}

I need a function that goes through a block of dynamically returned text and puts all of the images contained within into an array (or more specifically the image source of each image). The function above only gives me the first image and I cannot work out how to make this loop keep happening until all of the images are in the array. Any help on this would be much appreciated. Thanks

+6  A: 

You may want to investigate preg_match_all. If I recall correctly, preg_match only searches for the first match and then stops.

Phill Sacre
Cheers man, works like a treat.
Drew
+2  A: 

You are very close! You just need preg_match_all instead of preg_match.

Daniel Von Fange
Cheers as well dude!
Drew
A: 

I don´t know how well you know your source, but you might want to allow single quotes for the src attribute.

jeroen