<?php
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<root>
<item>
<foo id=\"1\"><![CDATA[123]]></foo>
<bar><![CDATA[abc]]></bar>
</item>
<item>
<foo id=\"1\">123</foo>
<bar>abc</bar>
</item>
</root>";
$sxml = simplexml_load_string($xml, null, LIBXML_NOCDATA);
print_r($sxml);
print_r($sxml->item[0]->foo["id"]);
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.16, 7.3.18 - 7.3.33, 7.4.0 - 7.4.4, 7.4.6 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- SimpleXMLElement Object
(
[item] => Array
(
[0] => SimpleXMLElement Object
(
[foo] => 123
[bar] => abc
)
[1] => SimpleXMLElement Object
(
[foo] => 123
[bar] => abc
)
)
)
SimpleXMLElement Object
(
[0] => 1
)
- Output for 7.3.17, 7.4.5
- SimpleXMLElement Object
(
[item] => Array
(
[0] => SimpleXMLElement Object
(
[foo] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1
)
[0] => 123
)
[bar] => abc
)
[1] => SimpleXMLElement Object
(
[foo] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1
)
[0] => 123
)
[bar] => abc
)
)
)
SimpleXMLElement Object
(
[0] => 1
)
preferences:
128.82 ms | 410 KiB | 5 Q