php把xml数据转化为数组
作者:
风度翩翩的程序猿 | 来源:发表于
2021-04-15 13:54 被阅读0次//将 xml数据转换为数组格式。
private 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] = $this->xml_to_array($subxml);
} else {
$arr[$key] = $subxml;
}
}
}
return $arr;
}
本文标题:php把xml数据转化为数组
本文链接:https://www.haomeiwen.com/subject/jsmdlltx.html
网友评论