');
// create an instane of the EXPAT XML parser
$xml_parser = xml_parser_create();
// set element start and end element handler functions
xml_set_element_handler($xml_parser, 'startElement', 'endElement');
// set character data handler function
xml_set_character_data_handler($xml_parser, 'handleData');
xml_set_default_handler($xml_parser, 'defaultHandler');
// activate the XML parser
$parsed = xml_parse($xml_parser, $shoutcast_xml, 1);
// some debugging code
if (DEBUG) {
echo $shoutcast_xml;
print_r ($shoutcast_data);
}
// check that the parsing operation worked correctly
if ($parsed) {
// it worked, so report the station status
if ($shoutcast_data['streamstatus'] == '1') {
// streaming content is available
echo '';
echo $shoutcast_data['servertitle'];
echo '
Streaming at ';
echo $shoutcast_data['bitrate'];
echo ' kbps.
';
echo 'Currently playing: ';
echo $shoutcast_data['songtitle'];
echo '
';
echo 'Current listeners: ';
echo $shoutcast_data['currentlisteners'];
echo ' (only ';
echo $shoutcast_data['maxlisteners'];
echo ' allowed).
';
if (intval($shoutcast_data['currentlisteners'])
< intval($shoutcast_data['maxlisteners'])) {
echo "If you have Real Player installed, then ";
echo "click the Play button on the console above. ";
echo "Otherwise, to listen using Winamp ";
echo "click here.
";
} else {
echo "Please wait until another listener can be added.
";
}
} else {
// no streaming content is available
echo 'The station is online but service has been interrupted.
';
}
}
else {
// parsing failed
if (DEBUG) {
echo 'XML Parser reported the following error:' . '
';
echo xml_error_string(xml_get_error_code($xml_parser)) . ' in line ';
echo xml_get_current_line_number($xml_parser) . '
';
}
}
// the xml parser is no longer required
xml_parser_free($xml_parser);
} else {
// socket connection could not be established
echo 'The station is offline.
';
}
?>