Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 读取SimpleXmlElement对象_Php_Cakephp_Xml Parsing - Fatal编程技术网

Php 读取SimpleXmlElement对象

Php 读取SimpleXmlElement对象,php,cakephp,xml-parsing,Php,Cakephp,Xml Parsing,我需要解析以下xml Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [rel] => http://schemas.google.com/g/2005#other [address] => xyz@gmail.com [primary] =&g

我需要解析以下xml

Array
(
 [0] => SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [rel] => http://schemas.google.com/g/2005#other
                [address] => xyz@gmail.com
                [primary] => true
            )

    )

[1] => SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [rel] => http://schemas.google.com/g/2005#other
                [address] => abc@gmail.com
                [primary] => true
            )

    )
)
我有上面的xml,我只需要从这个xml中获取地址

foreach ($result as $title) {
   $email[$count++]=$title->attributes()->address->__toString; 
}
debug($email);
结果就是这样。但我只想要地址。我需要一些帮助

Array
(
[0] => SimpleXMLElement Object
    (
    )

[1] => SimpleXMLElement Object
    (
    )
)
见:

返回值

返回一个SimpleXMLElement对象,可以对该对象进行迭代以循环遍历标记上的属性

解决方案是将值转换为字符串,
例如:

$email[$count++]=(string)$title->attributes()->address;
或者迭代返回值也可以

例如:


这可能有助于
$email[$count++]=(string)$title->attributes()->address是的..这很有效…你能把它作为答案添加吗?
foreach($title->attributes() as $key => $val)
{
  if ($key == 'address') $email[$count++] = $val;
}