Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Help on extract url and image

  •  06-25-2008, 9:26 AM

    Help on extract url and image

    Hello how's everyone doin'? I need help with the regular expression in PHP (using preg_match_all) that could extract the url and the image of these two:

    <A HREF="movie1.mpg"><img name="movie1" src="images/tn_01.jpg" width="320" height="240" border="0" alt="Play Movie" title="Play Movie" class="vid_th"></A>
    <a href="movie2.mpg"><img src="images/tn_01.jpg" width=320 height=240 border=0 class="fhg_vid"><br><img src="images/play.gif" width=320 height=48 border=0></a>

    If you notice on the second one, there are two image sources: "images/tn_01.jpg" and "images/play.gif". I would only need to extract the first image source ("images/tn_01.jpg").
    Also, I would only need to extract jpg image formats.

    Currently, my expression is:
    $expr = '@<a[^>]*href="([^"]*)"[^>]*>[^>]*<img[^>]*src="([^"]*)"[^>]*>[^>]*</a>@Usi';

    This works fine with the first given but it doesnt extract the jpgs with the second one. I'm new with regexp so i'm still a little confused. I would appreciate it very much if you could provide an explanation with your expression.

    Thanks much! have a nice day y'all!!!

View Complete Thread