You are here: Re: Regular Expression to extract all .JPG and .PNG URL's « PHP Programming Language « IT news, forums, messages
Re: Regular Expression to extract all .JPG and .PNG URL's

Posted by Steve on 10/12/07 15:51

"Steve" <no.one@example.com> wrote in message
news:ZnMPi.30$3d2.24@newsfe06.lga...
>
> <kosanovic@gmail.com> wrote in message
> news:1192201960.982311.106940@i13g2000prf.googlegroups.com...
>> Hello,
>> I'm bad at regular expressions. Would somebody help me:
>> I need to extract all URL to .jpg and .png pictures from a string
>> containing an HTML file (DOM wouldn't work well in what I need).
>>
>> I've tried:
>>
>> preg_match_all("/.jpg$|.png$/", $htmlfile, $Matches);
>> foreach ($Matches as $match)
>> {
>> echo $match."<br>";
>> }
>
> \.(jpe?g|png)\b+$?

sorry...if you're screen scaping, then the image may be in a src tag
attribute and will no doubt be quoted or tic'd. the above will only handle
unquoted/tic'd where the src value (this image link) is not ended with the
closing tag. all that said, see if you can tell how the changes below meet
the constraints/problems not covered by the former...

=(["'])?(([^\.]*\.)*(jpe?|pn)g)\1[^>]*?>

again, i haven't tested it...but the raw image (including the path, i.e.
http://www.example.com/images/image.png) should be the second match captured
by preg_match_all. to make sure of that, do this:

preg_match_all($pattern, $search, $matches);
echo '<pre>' . print_r($matches, true) . '</pre>';

hth,

me

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация