php下将XML转换为数组_PHP

WBOY
Release: 2016-06-01 12:22:31
Original
746 people have browsed it
复制代码 代码如下:
// Xml 转 数组, 包括根键
function xml_to_array( $xml )
{
$reg = "/]*>([\\x00-\\xFF]*)/";
if(preg_match_all($reg, $xml, $matches))
{
$count = count($matches[0]);
for($i = 0; $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;
}
// Xml 转 数组, 不包括根键
function xmltoarray( $xml )
{
$arr = xml_to_array($xml);
$key = array_keys($arr);
return $arr[$key[0]];
}
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!