php 利用正则将xml数据解析为数组
利用正则将xml数据解析为数组 [代码片段(21行)]
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;
}
//该片段来自于http://outofmemory.cn
- 上一篇:php 爬小说站
- 下一篇:php 解析百度搜索结果link?url=
精彩图集
精彩文章






