Heim  >  Artikel  >  Backend-Entwicklung  >  php下将XML转换为数组_PHP教程

php下将XML转换为数组_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:42:03710Durchsuche

复制代码 代码如下:

// 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]];
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321043.htmlTechArticle复制代码 代码如下: // Xml 转 数组, 包括根键 function xml_to_array( $xml ) { $reg = "/(\w+)[^]*([\\x00-\\xFF]*)\\/\\1/"; if(preg_match_all($reg, $xml, $matches)) { $c...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn