Re: preg_match_all issue, need some help



If you are going to be passing raw html into a preg_match, you should
probably escape regular expression characters first.
Try using preg_quote()

http://www.php.net/preg_quote

As for your expression, I think you might be able to get away with
using the following:

<?php
preg_match_all('/<img[^>]*>/i',preg_quote($html, '/') ,$images);
?>

I'd recommend using the case insensitive search (/i) so that you can
match IMG or img or ImG.

I am pretty sure this does what you want, I hope it helps.

On Feb 27, 8:33 pm, dysfunct <Dysfunct...@xxxxxxxxx> wrote:
I'm running a script that at one point will collect <img> tags from
some html. I've been using the following:

preg_match_all("/<img .*?>/",$html,$images);

and I thought it was working well. However, I've notice that some
things i throw at it don't work properly. It seems to be that and
image tag closing itself with "/>" doesn't work, ie <img src=".....
" /

. I'm guessing the "/" character is delimiting the regex somehow.

Admittedly I know very little about regular expressions. Anyone know
whats going on and the best way to get all the image tags? I ideally
would like the whole thing, from the <img to the final closing bracket

.