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)


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)

5+ Year Member


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>';

Featured Threads

Hot Threads This Week

Hot Threads This Month