Convert PHPXML to an array function. Convert PHPXML to an array function? Phpfunctionxml2array ($ originalXML, $ attributestrue) {$ xmlArrayarray (); $ search $ attributes? | (S) (. *) s *(.*)? Phpfunctionxml2array ($ origin 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.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486203.htmlTechArticlePHP XML conversion to array functions? Php function xml2array ($ originalXML, $ attributes = true) {$ xmlArray = array (); $ search = $ attributes? | (S) (. *) s *(.*)/? Php function xml2array ($ origin...