Problema ao trabalhar com XML
Estou tentando pegar dados do SHOUTCAST, no arquivo XML que o SHOUTCAST gera com as informações...
Segue meu código:
<?php
$radiowp = array();
$xmlradiowp = array();
$error = 0;
$queryStatus = db::Assoc(db::Query("SELECT * FROM radio_dados ORDER BY id ASC LIMIT 1"));
$ipwp = $queryStatus['ip'];
$portwp = $queryStatus['port'];
$ippwp = $ipwp.":".$portwp;
$passwp = $queryStatus['senha_radio'];
// Change IP_RADIO_PORT to your <myradioip>:<port> and RADIO_PASS to your <adminpass>
define($ipwp.":".$portwp, $ipwp.":".$portwp);
define($passwp, 'xxxxx');
// Url of admin area in shoutcast
$file = 'http://'.$ippwp.'/admin.cgi?user=admin&pass='.$passwp.'&mode=viewxml&sid=1';
// Retrieving shoutcast radiowp
if(!$xml = simplexml_load_file($file))
{
// If something goes wrong, keep the error message
$error = 1;
$radiowp['message'] = 'Ops, o servidor caiu! Rapidinho consertamos, volte em breve!';
}
// If nothing went wrong...
if($error < 1)
{
// Convert xml to array
$xmlradiowp = xml2array($xml);
// Uncomment to see all information retrieved
// print('<pre>'); print_r($xmlradiowp); die;
// Check if server is up
if($xmlradiowp['STREAMSTATUS'] == 1)
{
$radiowp['locutor'] = $xmlradiowp['SERVERTITLE']; // Radio Title
$radiowp['radiourl'] = $xmlradiowp['SERVERURL']; // Radio Url
$radiowp['radiogenre'] = $xmlradiowp['SERVERGENRE']; // Radio Genre
$radiowp['nowplaying'] = $xmlradiowp['SONGTITLE']; // Now playing
$radiowp['nextsong'] = $xmlradiowp['NEXTTITLE']; // Next song in queue
$radiowp['listeners'] = $xmlradiowp['UNIQUELISTENERS']; // How many is listening right now
$radiowp['songhistory'] = $xmlradiowp['SONGHISTORY']['SONG']; // Song history
}
else
{
// If server is down, keep the error message
$error = 1;
$radiowp['message'] = 'Ops, o servidor caiu! Rapidinho consertamos, volte em breve!';
}
}
/**
* [http://www.php.net/manual/en/ref.simplexml.php#111227](http://www.php.net/manual/en/ref.simplexml.php#111227)
* @param unknown $xmlObject
* @param unknown $out
* @return unknown
*/
function xml2array ( $xmlObject, $out = array () )
{
foreach ( (array) $xmlObject as $index => $node )
$out[$index] = ( is_object ( $node ) || is_array ( $node ) ) ? xml2array ( $node ) : $node;
return $out;
}
?>Discussão (7)
Carregando comentários...