复制代码 代码如下:
thread as $th) //循环读取xml数据中的每一个thread标签
{
echo 标题:.$th->title.
;
echo 作者:.$th->author.
;
echo 内容:.$th->content.
;
echo ;
}
?>
复制代码 代码如下:
load('db/guestbook.xml'); //读取xml数据
$threads = $guestbook->documentelement; //获得xml结构的根
//创建一个新thread节点
$thread = $guestbook->createelement('thread');
$threads->appendchild($thread);
//在新的thread节点上创建title标签
$title = $guestbook->createelement('title');
$title->appendchild($guestbook->createtextnode($_post['title']));
$thread->appendchild($title);
//在新的thread节点上创建author标签
$author = $guestbook->createelement('author');
$author->appendchild($guestbook->createtextnode($_post['author']));
$thread->appendchild($author);
//在新的thread节点上创建content标签
$content = $guestbook->createelement('content');
$content->appendchild($guestbook->createtextnode($_post['content']));
$thread->appendchild($content);
//将xml数据写入文件
$fp = fopen(db/guestbook.xml, w);
if(fwrite($fp, $guestbook->savexml()))
echo 留言提交成功;
else
echo 留言提交失败;
fclose($fp);
?>
复制代码 代码如下:
br>http://www.w3.org/tr/html4/loose.dtd>
发表新的留言