m-eye Posted March 23, 2014 Share Posted March 23, 2014 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 var_dump Output: object(SimpleXMLElement)#2 (2) { ["@attributes"]=> array(1) { ["seq"]=> string(2) "44" } ["data"]=> object(SimpleXMLElement)#3 (1) { ["eventlist"]=> object(SimpleXMLElement)#4 (1) { ["event"]=> object(SimpleXMLElement)#5 (5) { ["@attributes"]=> array(1) { ["type"]=> string(5) "relay" } ["relay"]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(2) { ["priority"]=> string(1) "1" ["url"]=> string(18) "127.0.0.1:8000" } } ["active"]=> string(1) "1" ["id"]=> string(1) "1" ["calendar"]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(1) { ["starttime"]=> string( "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 Link to comment https://forums.phpfreaks.com/topic/287213-curl-post-array-shoutcast2/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.