preg_match_all help

I am using the code below to search for the first image in a post on a Wordpress blog:

[php]preg_match_all(’/<img.+src=’"[’"].*>/i’, $post->post_content, $matches);
if ( isset( $matches ) ) {
$url = $matches[1][0];
}
[/php]

I really want to search for the first image in a post that has an underscore “_” in the url, can this be done?

Try to replace this pattern: b[/b]
with this: b[/b]
keeping the rest of your code as is.

And also, if you need only 1st instance, you can use preg_match() instead of preg_match_all().

Sponsor our Newsletter | Privacy Policy | Terms of Service