Php xml Conversion to array Functions
- <? Php
- Function xml2array ($ originalXML, $ attributes = true)
- {
- $ XmlArray = array ();
- $ Search = $ attributes? | <(S) (. *) s *> (. *) </<? Php
Function xml2array ($ originalXML, $ attributes = true)
{
$ XmlArray = array ();
$ Search = $ attributes? | <(S )(. *) s *> (. *) </2> | Ums: | <(S )()). *> (. *) </2> | 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> </$1>, $ 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) (). *> (. *) </<? Php
Function xml2array ($ originalXML, $ attributes = true)
{
$ XmlArray = array ();
$ Search = $ attributes? | <(S )(. *) s *> (. *) </2> | Ums: | <(S )()). *> (. *) </2> | 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> </$1>, $ 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] <? Php
Function xml2array ($ originalXML, $ attributes = true)
{
$ XmlArray = array ();
$ Search = $ attributes? | <(S )(. *) s *> (. *) </2> | Ums: | <(S )()). *> (. *) </2> | 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> </$1>, $ 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;
}
?> </[Code]>, $ 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