将simplexml转化成数组
span style=color:#008080;span style=font-size:14px;line-height:normal;出处:/span/span a href=http://fayaa.com/code/view/7350/http://fayaa.com/code/view/7350//a
出处:
http://fayaa.com/code/view/7350/
<?php
/**
* convert simplexml object to array sets
* $array_tags 表示需要转为数组的 xml 标签。例:array('item', '')
* 出错返回False
*
* @param object $simplexml_obj
* @param array $array_tags
* @param int $strip_white 是否清除左右空格
* @return mixed
*/
function simplexml_to_array($simplexml_obj, $array_tags=array(), $strip_white=1)
{
if( $simplexml_obj )
{
if( count($simplexml_obj)==0 )
return $strip_white?trim((string)$simplexml_obj):(string)$simplexml_obj;
$attr = array();
foreach ($simplexml_obj as $k=>$val) {
if( !empty($array_tags) && in_array($k, $array_tags) ) {
$attr[] = simplexml_to_array($val, $array_tags, $strip_white);
}else{
$attr[$k] = simplexml_to_array($val, $array_tags, $strip_white);
}
}
return $attr;
}
return FALSE;
}
?>
- 上一篇:将数组转换为XML
- 下一篇:PHP缩略图,满窗格等比例缩小
精彩图集
精彩文章






