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 16:00

"Captain Paralytic" <paul_lautman@yahoo.com> wrote in message
news:1192202883.609210.175920@k35g2000prh.googlegroups.com...
> On 12 Oct, 16:12, kosano...@gmail.com wrote:
>> 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>";
>> }
>>
>> without much success. Anybody can correct this to make it work?
>
> Try:
> preg_match_all("/.*(jpg|png)$/", $htmlfile, $Matches);

nah...that would mean:

ghijpgklmno

or

mnopngqrst

or any text having those letters within it would be captured. however,
neither his nor yours work unless the string ends at the end of the line
(eof or \r or \n). both don't escape the dot...so that means 'any character
followed by jpg or png'. more marginal success would be had just doing,
"/\.jpg|\.png/", but even that doesn't cut it...since either jpg or png can
be followed by anything and still be captured. not to mention we've left out
jpeg's.

make sense?

 

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

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