Welcome to the Linux community forum and interact with 2 million technical staff. Use php to convert xml data into an array: Convert xml into an array, use regular expressions to match xml data. code: functionxml_to_array ($ xml) {$ reg "(w +) [^] * ([x00-xFF] *) 1"; if (preg_match_all
Welcome to the Linux community forum and interact with 2 million technical staff> go to php to convert xml data into an array: Convert xml into an array, use regular expressions to match xml data. the Code is as follows: function xml_to_array ($ xml) {$ reg = "/(\ w +) [^] * ([\ x00-\ xFF] *) \/\ 1/"; if (preg_match_all
Welcome to the Linux community forum and interact with 2 million technicians>
Use php to convert xml data into an array ):
Convert xml into an array and use a regular expression to match xml data. The Code is as follows:
Function xml_to_array ($ xml ){
$ Reg = "/<(\ w +) [^>] *> ([\ x00-\ xFF] *) <\/\ 1> /";
If (preg_match_all ($ reg, $ xml, $ matches ))
{
$ Count = count ($ matches [0]);
For ($ I = 0; $ I <$ count; $ I ++)
{
$ Subxml = $ matches [2] [$ I];
$ Key = $ matches [1] [$ I];
If (preg_match ($ reg, $ subxml ))
{
$ Arr [$ key] = xml_to_array ($ subxml );
} Else {
$ Arr [$ key] = $ subxml;
}
}
}
Return $ arr;
}
Function xmltoarray ($ xml ){
$ Arr = xml_to_array ($ xml );
$ Key = array_keys ($ arr );
Return $ arr [$ key [0];
}