Something is not quite working on this script. It is written to retrieve a "server status" and display the server name and population for the output, but for some reason it is only showing a blank page.
I have looked and looked at it - does anyone see anything wrong with this code?
Thanks in advance!
<?php
$insideitem = false;
$tag = "";
$da_server = "";
$da_population = "";
$da_type ="";
$da_status = "";
$da_totalpop=0;
$da_boxcontent="";
function startElement($parser, $tagName, $attrs) {
global $insideitem, $tag, $da_server, $da_type;
if ($insideitem) {
$tag = $tagName;
} elseif ($tagName == "SERVER") {
$insideitem = true;
while (list ($key, $val) = each ($attrs)) {
switch($key) {
case "NAME":
$da_server=$val;
break;
case "TYPE":
$da_type=$val;
break;
} // end case
} // end while
}
}
function characterData($parser, $data) {
global $insideitem, $tag, $da_server, $da_population, $da_type, $da_status,$da_totalpop;
if ($insideitem) {
switch ($tag) {
case "POPULATION":
$da_population .= $data;
$da_totalpop += $data;
break;
case "STATUS":
$da_status .= $data;
break;
}
}
}
function endElement($parser, $tagName) {
global $insideitem, $tag, $da_server, $da_population, $da_type, $da_status, $da_realmurl, $da_boxcontent;
if ($tagName == "SERVER") {
$da_boxcontent .= "<TR><TD><font size=2><A HREF=http://www.camelotherald.com/realms/";
$da_boxcontent .= "$da_server><b>$da_server</b></A>";
if ($da_type) {
$da_boxcontent .= "(<i>$da_type</i>)";
}
$da_boxcontent .= "</font></TD>";
$da_boxcontent .= "<TD align=center><font size=2>$da_status</font></TD>";
$da_boxcontent .= "<TD align=right><font size=2>$da_population</font></TD></TR>\n";
$da_server = "";
$da_population = "";
$da_status = "";
$da_type = "";
$insideitem = false;
}
}
// gotta have this for the php-NUKE block stuff to work
// returns a string with the Status Info (DHR)
function make_daoc() {
global $da_totalpop, $da_boxcontent;
$da_realmurl="http://www.camelotherald.com/realms/";
// Create an XML parser
$xml_parser = xml_parser_create();
// Set the functions to handle opening and closing tags
xml_set_element_handler($xml_parser, "startElement", "endElement");
// Set the function to handle blocks of character data
xml_set_character_data_handler($xml_parser, "characterData");
// print "<hr>\n";
$da_boxcontent .= "<TABLE BORDER=0 WIDTH=0%>\n<TR>\n";
// Open the XML file for reading
$fp = @fopen("http://www.camelotherald.com/xml/servers.xml","r");
if ($fp) {
$da_boxcontent .= "<TD><font size=2><B>Server</B></font></TD><TD><font size=2><B>Status</B></font></TD><TD><font size=2><B>Users</B></font></TD>\n";
$da_boxcontent .= "</TR>\n";
// Read the XML file 4KB at a time
while ($data = fread($fp, 4096)) {
// Parse each 4KB chunk with the XML parser created above
if (!(xml_parse($xml_parser, $data, feof($fp)))) {
$da_boxcontent .= "XML error:";
$da_boxcontent .= xml_error_string(xml_get_error_code($xml_parser));
$da_boxcontent .= "at line ";
$da_boxcontent .= xml_get_current_line_number($xml_parser);
break;
}
}
// Close the XML file
fclose($fp);
$da_boxcontent .= "<TR><TD><font size=2>Total Users</font></TD><TD></TD><TD align=right><font size=2>$da_totalpop</font></TD></TR>\n";
} else {
$da_boxcontent .= "<TD>Unavailable</TD></TR>\n";
}
$da_boxcontent .= "</TABLE>\n";
// Free up memory used by the XML parser
xml_parser_free($xml_parser);
return $da_boxcontent;
}
$content .= make_daoc();
?>