/**
*@name array2xml 將一維數組轉化為xml格式字符串輸出
*@retrn $xml-string for xml type
*/
function array_to_xml($arr,$encoding)
{
$encoding = $encoding=='' ? 'ISO-8859-1':$encoding;
if(!empty($arr)){
$obj_dom = new DOMDocument("1.0",$encoding);
//header("Content-Type: text/plain");
$root = $obj_dom->createElement($arr[0],'');
$obj_dom->appendChild($root);
foreach($arr as $rk=>$rv){
if($rk!='0'){
$item = $obj_dom->createElement($rk,$rv);
$root->appendChild($item);
}
}
$xml = $obj_dom->saveXMl();
}
else $xml = '';
return $xml;
}
$req_arr = array('request','msgType'=>'SvtGet3GUserInfReq','uid'=>'123456789','pageSize'=>1,'pageNo'=>0);
$encoding = 'UTF-8';
$xml = array_to_xml($req_arr,$encoding);
echo $xml;