PHP get values from SimpleXMLElement array

Posted by seanp2k on Stack Overflow See other posts from Stack Overflow or by seanp2k
Published on 2010-05-01T22:09:14Z Indexed on 2010/05/01 22:17 UTC
Read the original article Hit count: 139

Filed under:
|
|
|
|

I have this:

  [1]=>
object(SimpleXMLElement)#6 (1) {
  ["@attributes"]=>
  array(14) {
    ["name"]=>
    string(5) "MySQL"
    ["acknowledged"]=>
    string(1) "1"
    ["comments"]=>
    string(1) "1"
    ["current_check_attempt"]=>
    string(1) "1"
    ["downtime"]=>
    string(1) "0"
    ["last_check"]=>
    string(19) "2010-05-01 17:57:00"
    ["markdown_filter"]=>
    string(1) "0"
    ["max_check_attempts"]=>
    string(1) "3"
    ["output"]=>
    string(42) "CRITICAL - Socket timeout after 10 seconds"
    ["perfdata_available"]=>
    string(1) "1"
    ["service_object_id"]=>
    string(3) "580"
    ["state"]=>
    string(8) "critical"
    ["state_duration"]=>
    string(6) "759439"
    ["unhandled"]=>
    string(1) "0"
  }
}

(I used var_dump($child) to generate that)

How do I get the 'name' attribute out of there as a string?

Here is my code:

$xml = simplexml_load_string($results);

foreach($xml->data->list as $child) {
var_dump($child);
  echo $child->getName() . ": " . $child->name . "<br />";
  }

© Stack Overflow or respective owner

Related posts about php

Related posts about simplexml