Click to See Complete Forum and Search --> : finding text string in web pages inner html


llamatron
09-13-2003, 08:23 PM
I need to find a value in a webpage's inner HTML on an external domain. I was told how to do this by Pyro in Javascript but didn't realise at the time that because the page I need to interrogate resides on an external domain I cannot use Javascript & was hoping I could use embedded PHP to do it:

If i load up this web page and go to view/source it will say somewhere :

member_id=12345&

the id number can be of a variable length; the delimiter is the ampersand. I need to get that 12345 number from the html source code and somehow store it in a variable.
Does anyone know how to do this in PHP?
Thanks a lot,

pyro
09-13-2003, 10:53 PM
This should be that javasript in PHP:

<?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>";
}

?>

llamatron
09-14-2003, 09:26 AM
That's great, thanks dood :)

pyro
09-14-2003, 09:47 AM
You bet... :)