PHP XML why can't I read the first attribute with SimpleXML?
The XML file I want to read looks like this:
<issues aaa="444" exportTime="Tue Jul 28 23:54:39 CEST 2015">
<issue>
<name>Testing</name>
I am using this code:
$simple = file_get_contents('/url/test3.xml');
$test = new SimpleXMLElement($simple);
I can read the name of the problem name:
echo $test->issue[1]->name;
How can I read the ExportTime values?
echo $test->issues[exportTime]
doing nothing.
+3
Tass mark
source
to share
1 answer
Try
<?php
$str = <<<XML
<issues aaa="444" exportTime="Tue Jul 28 23:54:39 CEST 2015">
<issue>
<name>Testing</name>
</issue>
</issues>
XML;
$xml = new SimpleXMLElement($str);
var_dump($xml['exportTime']);
?>
OUTPUT
object(SimpleXMLElement)[2]
public 0 => string 'Tue Jul 28 23:54:39 CEST 2015' (length=29)
+1
Hassaan
source
to share