By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,964 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,964 IT Pros & Developers. It's quick & easy.

[Regex] Extracting multiple ocurrences from a page?

P: n/a
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_contents("http://localhost/stuff.html");

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

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

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

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

Thank you!
Jun 13 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.