By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,524 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

problem with some code..

P: n/a
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 http://www.worldofwarcraft.com*/serverstatus/ for
keywords
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,
Craft
______________________________*__________
$server = "Bonechewer";
$up = 'Up';
$down = 'Down';
$hig = 'High';
$med = 'Medium';
$low = 'Low';
// PHP Magic Below, Don't Edit
$html =
file_get_contents('http://www.worldofwarcraft.com*/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 =
"Roleplay";}
else if ($servertype == "Nor") {$length = $length + 3; $servertype =
"Normal";}
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
risk:
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>";

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Craft (cr*****@gmail.com) decided we needed to hear...
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 http://www.worldofwarcraft.com*/serverstatus/ for
keywords
and grab the information about the server that you're looking for. Can
anyone help me try and get the $serverpop part to work?
<snip code>
$serverpop = strtolower(substr(substr($html*, -(strlen($html) - ($pos
+
$length + 256))), 0, 3));

<snip>

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.

--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #2

P: n/a
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?

Jul 17 '05 #3

P: n/a
Craft (cr*****@gmail.com) decided we needed to hear...
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?


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
pointers.

--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.