2014-01-29 32 views
0

我已经SimpleXMLElement对象破折号看起来像这样SimpleXMLElement对象为@,重点

SimpleXMLElement Object (
    [report-name] = SimpleXMLElement Object 
     (
     [@attributes] = Array 
      (
      [name] = Raport 
      ) 

     ) 

    [date-range] = SimpleXMLElement Object 
     (
     [@attributes] = Array 
      (
      [date] = Jan 29, 2014 
      ) 

     )) 

我怎样才能摆脱这个“日期”值?

+0

您可以参考手册此。看到这个链接[http://in1.php.net/simplexmlelement.attributes](http://in1.php.net/simplexmlelement.attributes) – user2936213

回答

0

连字符( - )是问题,但你有孩子的方法,这将帮助你。

为了您更好的了解

<?php 

////xml which contains the hyphen 
$string = <<<XML 
<a> 
<x-y name="one" game="lonely">1</x-y> 
</a> 
XML; 

//load XML object 
$xml = simplexml_load_string($string); 

//process each children 
foreach($xml->children() as $a) 
{ 
    //collect the attributes and process it 
    foreach($a->attributes() as $b => $c) 
    { 
     //name and value of attribute 
     echo $b,'="',$c,"\"\n"; 

    } 
} 
2

来源:PHP websiteW3 Schools website

对于简单的XML对象的基本用法看到链接到W3学校。

解决与连字符您的问题看这个例子直接从PHP的网站,来了:

$xml = simplexml_load_string($input); 
$callback = $xml->{"callback-url"};