Click to See Complete Forum and Search --> : extracting data from html source


llamatron
09-19-2004, 03:07 PM
I was shown how to do this with the following code from Pyro of this board:


<?PHP

$contents = @file("http://www.somedomain.com/page.php");

$lines = "";
foreach ($contents as $line) {
$lines .= $line;
}

preg_match_all("/member_id=\d*&/",$lines, $matches);

for ($i=0;$i<count($matches[0]);$i++) {
preg_match("/member_id=(\d*)&/", $matches[0][$i], $results);
echo $results[1]."<br>";
}

?>

It reads the html source code, finds the number to the right of member_id and displays it on the screen. I have a problem now though:

There are about 9 unique member_id numbers in the page but they appear twice in the page's source code. I only want to display them once, this code will display them twice.

Thanks,

Jona
09-19-2004, 05:54 PM
Have a look at array_unique (http://php.net/array_unique).