Home > php教程 > php手册 > 利用正则将xml数据解析为数组

利用正则将xml数据解析为数组

WBOY
Release: 2016-06-06 19:32:32
Original
1504 people have browsed it

利用正则将xml数据解析为数组 此方法来源网络 无 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];$k

利用正则将xml数据解析为数组
此方法来源网络
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;
}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template