Ask a question about XML to PHP array
I'm now going to receive an XML content, not a file
The contents of the received file are formatted as follows
? 0000ax000011122233344212345 Test 402100002885328320130828 notes 1 remark 2 Note 3
How to directly convert this code to PHP array, this is not a file, is a variable
XML PHP
Share to:
------Solution--------------------
Find a Xml_to_array function, like
Http://www.cnblogs.com/heiing/archive/2009/12/31/1637015.html
Then use it
function Xml_to_array ($xml)
{
$reg = "/< (\\w+) [^>]*?> ([\\x00-\\xff]*?) <\\/\\1>/";
if (Preg_match_all ($reg, $xml, $matches))
{
$count = count ($matches [0]);
$arr = Array ();
for ($i = 0; $i < $count; $i + +)
{
$key = $matches [1][$i];
$val = Xml_to_array ($matches [2][$i]); Recursive
if (Array_key_exists ($key, $arr))
{
if (Is_array ($arr [$key]))
{
if (!array_key_exists (0, $arr [$key]))
{
$arr [$key] = Array ($arr [$key]);