zee100
Benutzer
Hallo Freunde.
Habe eine Frage zum Thema Shoutcast XML Parsing.
Nach langer Google Suche hab ich ein funktionstüchtiges XML Parsing Script für Shoutcast gefunden.
Bin aber immer noch php Anfängerin und komme damit nicht weiter.
Dieses Script gibt sämtliche Shoutcast XML Informationen bekannt.
Ich möchte aus diesem Script aber nur folgendes ausgelesen haben.
+ LISTENER
+ HOSTNAME xx.xx.xx.xx
+ USERAGENT WinampMPEG/5.24
+ UNDERRUNS
+ CONNECTTIME 52733
+ POINTER
+ UID 214690
IP Adresse hab ich jetzt mal entfernt.
Das + Zeichen sollte möglichst nicht mit angezeigt werden.
Hier mal das Script.
Wenn mir eventuell jemand dabei helfen könnte, währe ich sehr dankbar.
Grüsse
Marion
Habe eine Frage zum Thema Shoutcast XML Parsing.
Nach langer Google Suche hab ich ein funktionstüchtiges XML Parsing Script für Shoutcast gefunden.
Bin aber immer noch php Anfängerin und komme damit nicht weiter.
Dieses Script gibt sämtliche Shoutcast XML Informationen bekannt.
Ich möchte aus diesem Script aber nur folgendes ausgelesen haben.
+ LISTENER
+ HOSTNAME xx.xx.xx.xx
+ USERAGENT WinampMPEG/5.24
+ UNDERRUNS
+ CONNECTTIME 52733
+ POINTER
+ UID 214690
IP Adresse hab ich jetzt mal entfernt.
Das + Zeichen sollte möglichst nicht mit angezeigt werden.
Hier mal das Script.
PHP:
<?
// grabxml 0.1.2 (php)
// 1-12-2001 t. pepper
// yay i made this
// yay i stole some of it off php.net's xml docs pages
// SET THESE VARIABLES
$password="xxxxxxxx";
$host="209.9.226.67";
$port="9660";
// you can change these event handlers to do whatever
// you want upon receiving the XML data. right now, they
// just dump the parsed xml in as pretty a way as they can
function startElement($parser, $name, $attrs) {
global $depth, $lastelem;
if($lastelem!='data') echo "\n";
for ($i = 0; $i < $depth[$parser]; $i++) echo " ";
echo "+ <b>$name</b> ";
$depth[$parser]++;
$lastelem='start';
}
function endElement($parser, $name) {
global $depth, $lastelem;
//echo "<b>/$name</b> ";
if ($lastelem=='data') echo "\n";
$depth[$parser]--;
}
function characterData($parser, $data) {
global $depth, $lastelem;
$data=trim($data);
if ($data) { echo $data; $lastelem='data'; }
}
// here we go
$depth = array();
$lastelem="";
// set up html
echo "<HTML>\n<HEAD><TITLE>XML parsing for $host:$port</TITLE></HEAD>\n<BODY><PRE>\n";
// connect to sc_serv
$sp=fsockopen($host,$port,&$errno,&$errstr,10);
if(!$sp) die("Could not contact $host:$port - $errstr\n");
set_socket_blocking($sp,false);
// send request
fputs($sp,"GET /admin.cgi?pass=$password&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n");
// fetch response, timeout if it takes > 15s
for($i=0; $i<30; $i++) {
if(feof($sp)) break; // exit if connection broken
$sp_data.=fread($sp,31337);
usleep(500000);
}
// strip HTTP headers so all we have is XML data
$sp_data=ereg_replace("^.*<\?xml ","<?xml ",$sp_data);
/* xml code goes here, here's a plain empty parser */
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $sp_data, 1)) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
// close up HTML
echo "</PRE></BODY></HTML>";
?>
Wenn mir eventuell jemand dabei helfen könnte, währe ich sehr dankbar.
Grüsse
Marion