www.webdeveloper.com
Results 1 to 4 of 4

Thread: Retrieve certain images without id.

  1. #1
    Join Date
    May 2006
    Posts
    122

    Exclamation Retrieve certain images without id.

    I'm retrieving all images in a section of my source code. I want it to skip all the images that have the id="blocker". I've tried using strpos to search for the id in the image src. I then try to skip the image with that id by using the 'continue' expression, but it's not working. I'm not too familiar with preg_match_all, so can someone see if they can get this to work for me. I'll be able to learn from it. Or if anyone has an easier script to do what I want, that would be even better. Thanks.




    //retrieve all images within the above string
    preg_match_all('#<img\s[^>]*src\s*=\s*[\'"]?([^\'"\s>]+)[\'"]?[\s>]#i', $matches[0], $images);
    foreach($images[1] as $image)
    {
    $ider = 'id="blocker"';
    $pos = strpos($image, $ider);


    if ($pos !== false) {
    continue;} else {


    echo "document.getElementById('randompic".$h."').style.visibility = \"visible\";";

    $h++;}
    }

  2. #2
    Join Date
    Dec 2005
    Location
    Queen Creek, AZ
    Posts
    1,564
    first thing to check is if your images array is being filled with anything, so do a:
    PHP Code:
    print_r($images);
    exit; 
    after your preg_match_all

    if you get a list of images you can proceed

    next, if the array is $images, you should be doing:
    PHP Code:
    foreach($images as $image
    //erlin!

  3. #3
    Join Date
    May 2006
    Posts
    122
    aha, you made me realize that I'm just pulling the source of the image and not the whole image tag. Thats why it can't read if there is an id. Can you alter my regular expression so it pulls the whole image tag instead of just the source? I'm trying to learn regular expressions, but they just make my head hurt at this point. thanks.

  4. #4
    Join Date
    May 2006
    Posts
    122
    nm i got it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles