homepage Welcome to WebmasterWorld Guest from 54.211.138.180
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
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




msg:4180457
 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




msg:4181095
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved