|
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]
|