一 代码
<a href="index.xml">输出创建的xml的文档</a>
<?php
$fopen = fopen ("index.xml","w"); //使用添加模式打开文件,文件指针指在表尾
$title='<?xml version="1.0" encoding="gb2312"?>
<rss xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
<channel>
<title>科技学院</title>
<link>http://www.kejixueyuan.com</link>
<description>科技学院</description>
<dc:creator>http://www.kejixueyuan.com</dc:creator>';
fwrite($fopen,$title); //写入头文件
$item="<item>
<title>编程</title>
<link>http://www.kejixueyuan.com</link>
<description>编程大全系统</description>
<pubDate>2017-03-08</pubDate>
</item>";
if (!fwrite($fopen,$item)){ //将数据写入到文件中
echo "写入内容失败!" ;
exit ;
}
fwrite($fopen,"</channel></rss>"); //将xml文件的结束符写入到文件中
fclose($fopen); //关闭文件
?>
二 运行结果
![](https://i-blog.csdnimg.cn/blog_migrate/705cce0babbd481f637a7830a3b1a902.png)