2014-06-29 68 views
0

您好我正在使用XML提要,我需要访问XML循环内的循环。如何访问嵌套的XML

基本上XML我是这样的:

<properties> 
    <property> 
     <images> 
      <image modified="2012-04-03 19:20:16">http://image.url/</image> 
      <image modified="2012-04-03 19:20:16">http://image.url/</image> 
      <image modified="2012-04-03 19:20:16">http://image.url/</image> 
      <image modified="2012-04-03 19:20:16">http://image.url/</image> 
      <image modified="2012-04-03 19:20:16">http://image.url/</image> 
      <image modified="2012-04-03 19:20:16">http://image.url/</image> 
     </images> 
    </property> 
</properties> 

我有这样的循环:

foreach($xml->property as $property) { 
    foreach($property->images->image as $key => $value) { 
     print_r($value); 
    } 
} 

但$值返回[@属性] =>数组([改性] => 2013年10月3日十一点53分47秒

我想http://image.url/归还。

任何IDE如?

感谢,

汤姆

回答

2

您需要将值转换为像字符串:

foreach($xml->property as $property) { 
    foreach($property->images->image as $img) { 
     $value = (string) $img; 
     echo $value; 
    } 
} 
+0

这是伟大的工作,当我赞同,但由于某种原因,当我把它在MySQL查询将其设置到它放入0的数据库中。你知道为什么吗? – Tom

+0

明白了!谢谢,这是Wordpress的一个问题。不管怎样,谢谢! – Tom

+0

没问题..我很高兴它的工作。 – Hardy