I have code that is reading server information and outputting data from a separate site. The below code is built to monitor several servers - and I only want to monitor ONE server. Let's assume the server name I wanted to monitor was "bobsled" - how would I pare down the below PHP info to read only information from the "bobsled" server?
Thanks! New to XML.
<?php
$insideitem = false;
$tag = "";
$da_server = "";
$da_population = "";
$da_type ="";
$da_status = "";
$da_totalpop=0;
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;
if ($tagName == "SERVER"
{
print "<TR><TD><b>$da_server</b>";
if ($da_type) { print "(<i>$da_type</i>)"; }
print "</TD>";
print "<TD>$da_status</TD>";
print "<TD>$da_population</TD></TR>\n";
$da_server = "";
$da_population = "";
$da_status = "";
$da_type = "";
$insideitem = false;
}
}
// gotta have this for the php-NUKE block stuff to work
global $da_totalpop;
// 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";
print "<TABLE BORDER=0 WIDTH=0%>\n<TR>\n";
print "<TD><B>Server</B></TD><TD><B>Status</B></TD><TD><B>Users</B></TD>\n";
print "</TR>\n";
// Open the XML file for reading
$fp = fopen(" or die("Error reading RSS data."
;
// Read the XML file 4KB at a time
while ($data = fread($fp, 4096))
// Parse each 4KB chunk with the XML parser created above
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
// Close the XML filef
fclose($fp);
print "<TR><TD>Total Users</TD><TD></TD><TD>$da_totalpop</TD></TR>\n";
print "</TABLE>\n";
// free up used memory
xml_parser_free($xml_parser);
?>
Thanks! New to XML.
<?php
$insideitem = false;
$tag = "";
$da_server = "";
$da_population = "";
$da_type ="";
$da_status = "";
$da_totalpop=0;
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;
if ($tagName == "SERVER"
print "<TR><TD><b>$da_server</b>";
if ($da_type) { print "(<i>$da_type</i>)"; }
print "</TD>";
print "<TD>$da_status</TD>";
print "<TD>$da_population</TD></TR>\n";
$da_server = "";
$da_population = "";
$da_status = "";
$da_type = "";
$insideitem = false;
}
}
// gotta have this for the php-NUKE block stuff to work
global $da_totalpop;
// 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";
print "<TABLE BORDER=0 WIDTH=0%>\n<TR>\n";
print "<TD><B>Server</B></TD><TD><B>Status</B></TD><TD><B>Users</B></TD>\n";
print "</TR>\n";
// Open the XML file for reading
$fp = fopen(" or die("Error reading RSS data."
// Read the XML file 4KB at a time
while ($data = fread($fp, 4096))
// Parse each 4KB chunk with the XML parser created above
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
// Close the XML filef
fclose($fp);
print "<TR><TD>Total Users</TD><TD></TD><TD>$da_totalpop</TD></TR>\n";
print "</TABLE>\n";
// free up used memory
xml_parser_free($xml_parser);
?>