Hey, I have a simple loop & gather question.

Discussion in 'PHP' started by Crayz, Dec 16, 2007.

  1. #1
    Hello, how would I specify a web page, such as:
    www.test.com/list.php

    And in this page, there would be hyperlinked images.

    Every image has its own unique id, and is used inside the hyper as follows:
    http://test.com/page2.php?id=x

    So what I want to do, is sort through this page, saving every id into my array variable.

    So say the first 2 images had id's 1 & 7, like
    http://test.com/page2.php?id=1
    http://test.com/page2.php?id=7

    I need the script to run through, and gather what is after ?id= , and store it into my variable $id[x];

    So I would have: $id[0] = 1; $id[1] = 7; and so on, until it gathers the id from every images hyperlink.

    Thanks!
     
    Crayz, Dec 16, 2007 IP
  2. Crayz

    Crayz Well-Known Member

    Messages:
    708
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    120
    #2
    I figured something out, but it doesn't loop through the source gathering every id, just the first one it finds.
    Here's the code, if anyone could build up on it:

    
      $start = strpos($find, 'id=', $index);
      if($start)
        {
        $start += 6;
        $index = $start;
        $end = strpos($find, ' ', $start);
        if($end)
          {
          $id = substr($find, $start, $end - $start);
          $index = $end;
          $list[$key] = $id;
          $key++;
          }
      }
    
    Code (markup):
    Thanks.
     
    Crayz, Dec 16, 2007 IP
  3. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is something to get you started, this will get all your image links from the page ($html) into $matches...

    preg_match_all("/<img src=\"([^']*?)\">/", $html, $matches);
    print_r($matches);
    PHP:
     
    Gawk, Dec 16, 2007 IP