preg_match_all issue, need some help

This is a discussion on preg_match_all issue, need some help within the PHP Language forums, part of the PHP Programming Forums category; I'm running a script that at one point will collect <img> tags from some html. I've ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008
dysfunct
 
Posts: n/a
Default preg_match_all issue, need some help

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

Reply With Quote
  #2 (permalink)  
Old 02-28-2008
Rik Wasmus
 
Posts: n/a
Default Re: preg_match_all issue, need some help

On Thu, 28 Feb 2008 02:30:58 +0100, dysfunct <DysfunctY2K@gmail.com> 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


preg_match_all("/<img[^>]*>/",$html,$images);

However, proper use of DOM & getElementsByTagName() could be more easily
maintained.

--
Rik Wasmus
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:26 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0