PHP XML conversion to an array function
-
- function Xml2array ($originalXML, $attributes =true)
- {
- $xmlArray = Array ();
- $search = $attributes? |< ((S) (. *)) s*> (. *) function Xml2array ($originalXML, $attributes =true)
{
$xmlArray = Array ();
$search = $attributes? |< ((S) (. *)) s*> (. *) | Ums: |< ((S) ()) .*> (. *) | Ums;
Normalize data
$xml = Preg_replace (|>s*<|, "><", $originalXML); One tag per line
$xml = Preg_replace (| |,, $xml); Remove XML declarations
$xml = Preg_replace (|< (S?) (. *)/>| U, <$1$2> , $xml); Expand singletons
if (! Preg_match_all ($search, $xml, $xmlMatches))
Return trim ($originalXML); Bail Out-no XML found
foreach ($xmlMatches [1] as $index = $key)
{
if (! isset ($xmlArray [$key])) $xmlArray [$key] = array ();
$xmlArray [$key] = Xml2array ($xmlMatches [4][$index], $attributes);
}
return $xmlArray;
}
? >>| Ums: |< ((S) ()) .*> (. *) function Xml2array ($originalXML, $attributes =true)
{
$xmlArray = Array ();
$search = $attributes? |< ((S) (. *)) s*> (. *) | Ums: |< ((S) ()) .*> (. *) | Ums;
Normalize data
$xml = Preg_replace (|>s*<|, "><", $originalXML); One tag per line
$xml = Preg_replace (| |,, $xml); Remove XML declarations
$xml = Preg_replace (|< (S?) (. *)/>| U, <$1$2> , $xml); Expand singletons
if (! Preg_match_all ($search, $xml, $xmlMatches))
Return trim ($originalXML); Bail Out-no XML found
foreach ($xmlMatches [1] as $index = $key)
{
if (! isset ($xmlArray [$key])) $xmlArray [$key] = array ();
$xmlArray [$key] = Xml2array ($xmlMatches [4][$index], $attributes);
}
return $xmlArray;
}
? >>| Ums;
- Normalize data
- $xml = Preg_replace (|>s*<|, "><", $originalXML); One tag per line
- $xml = Preg_replace (| |,, $xml); Remove XML declarations
- $xml = Preg_replace (|< (S?) (. *)/>| U, <[code] function Xml2array ($originalXML, $attributes =true)
{
$xmlArray = Array ();
$search = $attributes? |< ((S) (. *)) s*> (. *) | Ums: |< ((S) ()) .*> (. *) | Ums;
Normalize data
$xml = Preg_replace (|>s*<|, "><", $originalXML); One tag per line
$xml = Preg_replace (| |,, $xml); Remove XML declarations
$xml = Preg_replace (|< (S?) (. *)/>| U, <$1$2> , $xml); Expand singletons
if (! Preg_match_all ($search, $xml, $xmlMatches))
Return trim ($originalXML); Bail Out-no XML found
foreach ($xmlMatches [1] as $index = $key)
{
if (! isset ($xmlArray [$key])) $xmlArray [$key] = array ();
$xmlArray [$key] = Xml2array ($xmlMatches [4][$index], $attributes);
}
return $xmlArray;
}
?>> , $xml); Expand singletons
- if (! Preg_match_all ($search, $xml, $xmlMatches))
- Return trim ($originalXML); Bail Out-no XML found
- foreach ($xmlMatches [1] as $index = $key)
- {
- if (! isset ($xmlArray [$key])) $xmlArray [$key] = array ();
- $xmlArray [$key] = Xml2array ($xmlMatches [4][$index], $attributes);
- &nb
http://www.bkjia.com/PHPjc/486203.html www.bkjia.com true http://www.bkjia.com/PHPjc/486203.html techarticle PHP XML conversion to an array function? PHP function Xml2array ($originalXML, $attributes =true) {$xmlArray = array (); $search = $attributes? | ((S) (. *)) s* (. *)/?php function Xml2array ($origin ...
-