php入門–配列からxmlの変換方法

サンプルコード
function arr2xml($data, $root = true){
$str=””;
if($root)$str .= “<xml>”;
foreach($data as $key => $val){
if(is_array($val)){
$child = arr2xml($val, false);
$str .= “<$key>$child</$key>”;
}else{
$str.= “<$key><![CDATA[$val]]></$key>”;
}
}
if($root)$str .= “</xml>”;
return $str;
}

Comments are closed.