How does php parse xml tags that have both values ​​and attributes?
巴扎黑
巴扎黑 2017-06-14 10:50:11
0
1
768

use:

$xml   = simplexml_load_string($content);
$array = json_decode(json_encode((array) $xml), 1);

When parsing XML into an array in this way,
For:

<a name="aaaa">
    <b></b>
</a>    

and

<a>content</a> 

can be parsed correctly, but for this:

<a name="aaaa">content</a> 

You cannot get the name attribute, but you can only get the content content.

Is there any good way to deal with this problem?

巴扎黑
巴扎黑

reply all(1)
我想大声告诉你
$xml = simplexml_load_string($content);
foreach($xml->attributes() AS $a => $b) {

echo "$a = $b <br />";
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template