Forum Moderators: coopster

Message Too Old, No Replies

regex - img src

Solution for regex string

         

bubbasheeko

3:46 am on May 2, 2008 (gmt 0)

10+ Year Member



Hi,

I have been struggling with this one for the last day and a half and made some great progress, but I am stuck on one thing.

Currently I have a website that has articles on it and the 'index' of these articles takes the 4 more recent articles and pulls the first image out of it and makes a thumbnail for the listing. I am getting the img src with this:

preg_match('/<img.*?src=([\'"])([^"\1]+)\1/i', $article_result['article_content'], $match);

The issue I am having now is that I want to also grab the alt tag from the image in the content so that I can use it on the thumbnail.

Any suggestions on how I can modify the regex to grab the Alt tag?

vincevincevince

6:00 am on May 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



preg_match('/<img.*?src=([\'"])([^"\1]+)\1.*?alt=([\'"])([^"\2]+)\2/i', $article_result['article_content'], $match);

bubbasheeko

11:59 pm on May 2, 2008 (gmt 0)

10+ Year Member



Thanks Vince!

I ended up checking it separately, but will give yours a shot.

preg_match('/<img.*?src=([\'"])([^"\1]+)\1/i', $html, $match);

preg_match('/alt=([\'"])([^"\1]+)\1/i', $html, $alt_tags);