Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg match all and link



7:35 am on Aug 2, 2010 (gmt 0)

Inactive Member
Account Expired



how find in text only one image?

$text = 'text text <img src = "http://physics.unl.edu/dept/directories/images/gradpics/Cat.jpg" /> text text <img src = "www.url.com/image.gif" />';
preg_match_all('#http:[^<\s>]+[.](gif|png|jpe?g)#i', $text, $all_img);

11:49 am on Aug 3, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 29, 2008
posts: 65
votes: 0


Regex can be painful and a simple variation can brake the rule. I have use for project where I need to extract data the "PHP Simple HTML DOM Parser", this is a really nice library that will get all the images with minimum effort.

// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members