I have again a problem, I want to use in ShoutCast2 the API and have an array a problem.
$sc_host = 'IP';
$sc_port = 'PORT';
$sc_user = 'USER';
$sc_pass = 'PASSWORD';
mt_srand((double) microtime() * 1000000);
$seq = mt_rand(1, 100);
$post = 'op=listevents&seq=' . $seq;
$ch = curl_init($sc_host . '/api');
curl_setopt($ch, CURLOPT_PORT, $sc_port);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $sc_user . ':' . $sc_pass);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$curl = curl_exec($ch);
$xml = new SimpleXMLElement(utf8_encode($curl));
curl_close($ch);
Array Output:
Array (
[@attributes] => Array (
[seq] => 128
)
[data] => Array (
[eventlist] => Array (
[event] => Array (
[@attributes] => Array (
[type] => relay
)
[relay] => Array (
[@attributes] => Array (
[priority] => 1
[url] => IP:PORT
)
)
[active] => 1
[id] => 1
[calendar] => Array (
[@attributes] => Array (
[starttime] => 00:00:00
)
)
)
)
)
)
Now I want to read the output via array:
foreach ($xml->data->eventlist->event as $event ) {
echo $event ->type;
}
no issue is why? where is the error?
Thank you
EDIT ORIGINAL XML
<eventlist>
<event type="playlist|dj|relay">
<active/>
<id/>
<dj/>
<playlist loopatend="1|0" shuffle="1|0" priority="#">
nameofplaylist
</playlist>
<relay url=""/>
<calendar/>
</event>
<event ... />