/*---------------------------------
xml数据处理文件
author:fangzhen 3.28
----------------------------------*/
function xml_to_array($source, $type=0){
$xmlParser = xml_parser_create();
if(!xml_parse($xmlParser,$source,true)){ //判断xml格式的正确性
xml_parser_free($xmlParser);
return false;
}
//$type 0为字符串,1为文件
if($type==1){
$xmlStr = simplexml_load_file($source);
}else{
$xmlStr = simplexml_load_string($source);
}
$arrStr = array();
$source = serialize($xmlStr);
$source = str_replace('O:16:"SimpleXMLElement"', 'a', $source);
$arrStr = unserialize($source);
return $arrStr;
}
欢迎光临 PHP开发笔记 (http://phpvi.com/) | Powered by Discuz! 6.1.0 |