PHP ShoutCast cURL Array

lockcat

Erfahrenes Mitglied
Hallo liebe Freunde von tutorials.de,

ich habe mal wieder ein Problem was ich nicht gelöst bekomme und zwar verbinde ich mich zum Server "ShoutCast2"

PHP:
$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);

ein var_dump ergibt folgendes
PHP:
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(8) "00:00:00"
          }
        }
      }
    }
  }
}

Nun will ich jedoch nur bestimmte Daten auslesen


PHP:
foreach ($xml->data->eventlist->event as $event ) {

        echo $event ->type;


    }

Nur leider erhalte ich keine Ausgabe... Warum? kann mir jemand ein Tipp geben? wäre echt lieb

Gruß
 
Zuletzt bearbeitet:
Zurück