[Regex] Extracting multiple ocurrences from a page?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vincent Delporte

    [Regex] Extracting multiple ocurrences from a page?

    Hello

    I need to extract multiple occurends of the same type of item from a
    web page. The part I need looks like

    "id=123456"

    .... without the quotes, and add each found item into an associative
    array stuff[$code] by adding a comma and the new item.

    I'm not used to using regexes with PHP (5, FWIW), and am a bit lost at
    how to do this. Should I use eregi()? preg_match_all? Something else?
    And how to do this?

    Here's the code:
    ----------------
    $stuff = file_get_conten ts("http://localhost/stuff.html");

    if(eregi("Nothi ng found.",$stuff) ) {
    echo "Nothing found.";
    } else {

    if (eregi("id=[0-9]+",$stuff)) {
    preg_match_all ("|id=(\d+)| ", $stuff, $out,
    PREG_PATTERN_OR DER);

    //How to extract item from $out[]?
    stuff[$code] = stuff[$code] . "," . $out[1][1];
    }

    }
    ----------------

    Thank you!
Working...