例子,php生成xml文件的方法。
<?php
$path = '../../xml/bz_line.xml'; //生成xml存放路径
if(file_exists($path)) unlink($path);
$handle = fopen($path, 'w') ;
$xmlContent ='<?xml version="1.0" encoding="UTF-8"?>';//定义xml内容
$xmlContent .='<bz_line>';
//开始写入 xml
while ($row_rs_line = mysql_fetch_assoc($rs_line)){
$lcard = $row_rs_line['lcard'];
$lname =iconv("GB2312","UTF-8",$row_rs_line['lname']);
$xmlContent .="<li lcardid='".$lcard."'><lname>".$lname."</lname><lcard>".$lcard."</lcard></li>";
}
$xmlContent .='</bz_line>';
if($handle)
{
if(fwrite($handle, $xmlContent))
{
fclose($handle);
}
}
?>