Hi,
Why does this code not find picture links in text?
$text = 'text text <img src = "http://www.singlewheel.com/Scoots/PAV/Martin7PAV/42316.jpg" /> text text';
preg_match_all('#^http:\/\/(.*)\.(gif|png|jpg)$#i', $text, $all_img);
Hi,
Why does this code not find picture links in text?
$text = 'text text <img src = "http://www.singlewheel.com/Scoots/PAV/Martin7PAV/42316.jpg" /> text text';
preg_match_all('#^http:\/\/(.*)\.(gif|png|jpg)$#i', $text, $all_img);
Remove the ^ and $ and if you want to capture the url for later use surround in ()
preg_match_all('#(http:\/\/(.*)\.(gif|png|jpg))#i', $text, $all_img);
There are any number of ways to parse the DOM with PHP. Here is an example that does exactly what you want (gets every img src from the html string)
http://simplehtmldom.sourceforge.net/#fragment-11
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
Regular expressions are poorly suited for parsing HTML.