Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php $xml = simplexml_load_string('<root> <user id="1"> <name>Alice</name> <email>alice@example.com</email> <roles> <role>admin</role> <role>editor</role> </roles> </user> </root>'); echo $xml->user->name; // "Alice" echo $xml->user["id"]; // "1" (attribute) foreach ($xml->user->roles->role as $role) { echo $role . " "; // "admin", "editor" } // Convert to array $array = json_decode(json_encode($xml), true);
Result
Open