我的SimpleXMLElement对象看起来像这样
SimpleXMLElement Object (
[report-name] = SimpleXMLElement Object
(
[@attributes] = Array
(
[name] = Raport
)
)
[date-range] = SimpleXMLElement Object
(
[@attributes] = Array
(
[date] = Jan 29, 2014
)
) )我怎样才能从中得到一个'date‘值呢?
发布于 2014-06-13 18:32:12
来源:PHP website,W3 Schools website
有关简单XML对象的基本用法,请参阅W3学校的链接。
要解决连字符的问题,请参阅直接来自PHP网站的示例:
$xml = simplexml_load_string($input);
$callback = $xml->{"callback-url"};发布于 2014-01-29 19:02:40
连字符(-)是个问题,但您有子方法,这将对您有所帮助。
为了让你更好的理解
<?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";
}
}https://stackoverflow.com/questions/21428502
复制相似问题