homepage Welcome to WebmasterWorld Guest from 54.237.38.30
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
preg match all and link
Lolalola

10+ Year Member



 
Msg#: 4180455 posted 7:35 am on Aug 2, 2010 (gmt 0)

hi,

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

print_r($all_img);

 

redhatlab

5+ Year Member



 
Msg#: 4180455 posted 11:49 am on Aug 3, 2010 (gmt 0)

Hi,

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved