PDA

View Full Version : Simple reg expr...


rich w
April 23rd, 2006, 09:06
Hey to all,

Got a simple problem here.
I'm trying to read stuff in from a text file..it looks like this:

//PROCESSOR
bla bla bla bla
bla bla bla
//MEMORY
bla bla bla ba

Basically I want to be able to return all the data for the processor:

//PROCESSOR([^<>]*)//

Now that kind of works...except it returns all the processor data and everything beyond that. It's not detecting that next //


Here is the code if anyone wants to play:

<?php
function getinfo($url,$stat) {
$handle = fopen($url, "rb");
$contents = "";
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
$regs = Array ();
if (eregi("//$stat([^<>]*)//", $contents, $regs)) {
$info = $regs[1];
}
fclose($handle);
return $info;
}

echo getinfo("http://hyperion.universalns.com/raw-info.php",PROCESSOR);
?>

Can anyone help?

Cheers

rich w
April 23rd, 2006, 09:12
I got fed up, so I altered the actual text file so that it ended each stat with something unique...


<?php
function getinfo($url,$stat) {
$handle = fopen($url, "rb");
$contents = "";
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
$regs = Array ();
if (eregi("//$stat([^<>]*)//$stat", $contents, $regs)) {
$info = $regs[1];
}
$info = str_replace("//","",$info);
fclose($handle);
return $info;
}

echo getinfo("http://localhost:8081/test.php",PROCESSOR);
?>


Thanks anyway :)