problem with some code..

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

 have this code and I'm trying to get it to work. It mostly works, but
$serverpop does not seem to work. What it looks to me like this code
does is scan ­/serverstatus/ for
and grab the information about the server that you're looking for. Can
anyone help me try and get the $serverpop part to work?

Thanks in advance,
$server = "Bonechewer";
$up = 'Up';
$down = 'Down';

$hig = 'High';
$med = 'Medium';
$low = 'Low';

// PHP Magic Below, Don't Edit

$html =
file_get_contents(' ­/serverstatus/');
$server = str_replace("'", "'", $server);
$length = strlen($server);
$pos = strpos($html, $server);

$serverstatus = stristr(substr(substr($html, -(strlen($html) - $pos +
154)), 0 ,4), "up");
if ($serverstatus == false) {$serverstatus = "down"; $length = $length
+ 2;}
$servertype = substr(substr($html, -(strlen($html) - ($pos + $length +
117))), 0, 3);
if ($serverstatus == "up") $fontcolor=("00FF00");
if ($serverstatus == "down") $fontcolor=("FF0000");

if ($servertype == "(RP") {$length = $length + 1; $servertype =
else if ($servertype == "Nor") {$length = $length + 3; $servertype =
else {$length = $length + 2; $servertype= "PVP";}

$serverpop = strtolower(substr(substr($html­, -(strlen($html) - ($pos
$length + 256))), 0, 3));
if ($serverpop == "hig") $fontcolr=("FF0000");
if ($serverpop == "med") $fontcolr=("FFFFFF");
if ($serverpop == "low") $fontcolr=("FFFF00");

$serverstatus = $$serverstatus; $serverpop = $$serverpop;

//////////////////////////////­//////////// Output, Edit at your own

echo "<body bgcolor=black>";
echo "<font color=white><b>Server Name: </b></font>";
echo "<font color=4444FF><b>$server</b></font><br>";
echo "<font color=white><b>Server Type: </font>";
echo "<font color =\"$fontcolor\">";
echo "$servertype</font><br>";
echo "<font color=white><b>Server Status: </font>";
echo "<font color =\"$fontcolor\">";
echo "$serverstatus</font><br>";
echo "<font color=white>Server Load: </font>";
echo "<font color =\"$fontcolr\"> ";
echo "$serverpop </font></b> <br><br><br><br>";
echo "</body>";

Re: problem with some code..

Craft ( decided we needed to hear...
Quoted text here. Click to load it
<snip code>

Quoted text here. Click to load it

It all seems like a pretty slack way of parsing HTML to me, and not
very robust if the HTML changes - its crying out for a rewrite ;)

Your problem with serverpop is probably to do with the number 256
above... seems like thats meant to step past all of those blanks
in the HTML to actually get to the <TD> that contains the value
required. You could try doing some manual char counting in the HTML
file and in/de-creasing the 256 as appropriate - or by trial and
error, which ever suits you.

(Remove REMOVE for email address)

Re: problem with some code..

how would i count my friend help me code this but his pc just crashed
so he hasnt been online.. like iuno wtf

$serverpop = strtolower(substr(substr($html­­, -(strlen($html) -
($pos + $length + 256))), 0, 3));

is.. so uh can u help?

Re: problem with some code..

Craft ( decided we needed to hear...
Quoted text here. Click to load it

Well, if you still really want to do it the way you're doing it in the
script, the following *might* work (but untested)...
1) Grab the HTML file yourself (view in a browser, do a view source,
then copy/paste into an editor).
2) Count the number of chars from the end of the server name to the
start of the server pop (including newlines)
3) Replace the 256 with the value you got in 2.

If you're serious about making the script work, regardless of changes
to the HTML, you'd be better off investigating HTML parsing routines,
can't think of any off-hand but someone else might give you some

(Remove REMOVE for email address)

Site Timeline