ultrus Posted February 3, 2008 Share Posted February 3, 2008 Hello, I'm tweaking a WordPress template to show thumbnails of the first image in each post (if there is one) to represent each blog post link. To do that, I need to search the post HTML content for the first <img ... src='GOLDEN GOAL' ... /> or <img ... src="GOLDEN GOAL" ... />. Once I get the image source sting, I can rip it apart and get the WordPress thumbnail version on the image. This seems daunting at the moment due to a faded memory on patterns. Any clues on how to get started? Keep in mind that the ... in the image tag represent style, alt, class that were added to images in random order. hmmm. *begins brushing up on patterns Thanks for the assist Quote Link to comment Share on other sites More sharing options...
sasa Posted February 3, 2008 Share Posted February 3, 2008 try <?php $a = 'blah m <img >blah<a ><img blah src="aaaa" />sasa <img src=\'ddd"</a>'; preg_match('/<img[^>]+src=[\'"]([^\'"]*)/',$a,$b); print_r($b); ?> Quote Link to comment Share on other sites More sharing options...
ultrus Posted February 4, 2008 Author Share Posted February 4, 2008 sasa, That works like a charm! Thanks for the boost. I'm getting my patterns beefed up again now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.