Web Hosting Talk







View Full Version : ereg() trouble


CChard
05-29-2003, 11:52 PM
This script seems simple enough. Find out if this page: http://planetside.station.sony.com/network_status/server_status.jsp says "All servers are up" and then echo out a message.

Except it wont work: http://www.planetside.info/server.php

<?php
//URL for Status
$url = "http://planetside.station.sony.com/network_status/server_status.jsp";

if ( !($fp = fopen($url, "r")) )
{
echo "Could not connect to server.";
exit;
}
$contents = fread($fp, 31000);
fclose($fp);

$pattern = "All servers are up";

if ( eregi($pattern, $contents, $text) )
{
echo "<center><font color='green'>All Servers Are Online</font></center>";
}
else
{
echo "<center><font color='red'>Servers Are Offline</font></center>";
}
?>

Joe Bonanno
05-29-2003, 11:59 PM
Look at the code for the page given in your example. It is not "All servers are up" it is "...>All servers are up<..."

CChard
05-30-2003, 12:08 AM
It seems also that the fread($fp, 31000); is not getting enough of the page to reach that section.

I tried to up the value but that didn't work.

Joe Bonanno
05-30-2003, 12:38 AM
Try something like:

while (! feof($fp)) {
$contents = fread ($fp, 1048576);
}

fclose($fp);

This is not to say you should read a full megabyte of data, but you ought to be able to get to the text.

Joe Bonanno
05-30-2003, 01:31 PM
Heads up.

See this thread (http://www.webhostingtalk.com/showthread.php?s=&threadid=148950)

It looks as if there may be a bug with fread if you are using PHP 4.3.2 that is limiting your ability to read down to the desired text.