Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP SimpleXML-从字符串读取_Php_Xml - Fatal编程技术网

PHP SimpleXML-从字符串读取

PHP SimpleXML-从字符串读取,php,xml,Php,Xml,我正在PHP中使用simplexml\u load\u string。如何从该数组中获取numberofrecordings、recordingid、starttime和stoptime SimpleXMLElement Object ( [@attributes] => Array ( [totalnumberofrecordings] => 2 [numberofrecordings] => 2

我正在PHP中使用
simplexml\u load\u string
。如何从该数组中获取
numberofrecordings
recordingid
starttime
stoptime

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [totalnumberofrecordings] => 2
            [numberofrecordings] => 2
        )

    [recording] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [diskid] => SD_DISK
                            [recordingid] => 123123312
                            [starttime] => 2017-05-18T11:40:00.173775Z
                            [starttimelocal] => 2017-05-18T03:40:00.173775-08:00
                            [stoptime] => 2017-05-18T12:15:01.155311Z
                            [stoptimelocal] => 2017-05-18T04:15:01.155311-08:00
                            [recordingtype] => continuous
                            [eventid] => continuous
                            [eventtrigger] => continuous
                            [recordingstatus] => completed
                            [source] => 1
                            [locked] => No
                        )

                )
     )
)

假设
$xml
是您的xml对象

$numberofrecordings = $xml->attributes()->numberofrecordings;
$recordingid = $xml->recording[0]->attributes()->recordingid;
$starttime = $xml->recording[0]->attributes()->starttime;
$stoptime = $xml->recording[0]->attributes()->stoptime;
计数($array['recording'])?