标签:tox 函数 load bsp 1.0 str new 封装 dom
/**
* 数组转换为xml
*
* @param array $arr
* @param int $level
* @return string
*/
public static function arrayToXml($arr, $level = 0) {
$s = $level == 0 ? ‘<?xml version="1.0" encoding="UTF-8"?>‘ : ‘‘;
foreach ( $arr as $key => $value ) {
if (is_array ( $value )) {
$s .= "<" . $key . ">" . ArrayXML::arrayToXml ( $value, 1 ) . "</" . $key . ">";
} else {
$s .= "<" . $key . ">" . $value . "</" . $key . ">";
}
}
return $s;
}
/**
* xml转为数组
*
* @param string $xml
* @param string $version
* @param string $charset
* @return array
*/
public static function xmlToarray($xml, $version = "1.0", $charset = "utf-8") {
$doc = new DOMDocument ( $version, $charset );
$doc->loadXML ( $xml );
$result = domNodeToArray($doc);
if (isset ( $result [‘#document‘] )) {
$result = $result [‘#document‘];
}
return $result;
}
标签:tox 函数 load bsp 1.0 str new 封装 dom
原文地址:http://www.cnblogs.com/wzjdy/p/7297454.html