Php 读取SimpleXmlElement对象
我需要解析以下xmlPhp 读取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
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;
}