php xml实例 留言本

前端之家收集整理的这篇文章主要介绍了php xml实例 留言本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="85845" class="copybut" id="copybut85845" onclick="doCopy('code85845')"> 代码如下:

<div class="codebody" id="code85845">
<?PHP
//打开用于存储留言的XML文件
$guestbook = simplexml_load_file('DB/guestbook.xml'); foreach($guestbook->thread as $th) //循环读取XML数据中的每一个thread标签
{
echo "标题".$th->title."
";
echo "作者:".$th->author."
";
echo "内容
".$th->content."
";
echo "
";
}
?>

<div class="codetitle"><a style="CURSOR: pointer" data="77559" class="copybut" id="copybut77559" onclick="doCopy('code77559')"> 代码如下:
<div class="codebody" id="code77559">
<?PHP
$guestbook = new DomDocument(); //创建一个新的DOM对象
$guestbook->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);
?>

<div class="codetitle"><a style="CURSOR: pointer" data="55533" class="copybut" id="copybut55533" onclick="doCopy('code55533')"> 代码如下:
<div class="codebody" id="code55533">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;


发表新的留言
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">


<p align="center">发表新的留言


<form name="form1" method="post" action="Post.PHP">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>标题</td>
<td><input name="title" type="text" id="title" size="50"></td>
</tr>
<tr>
<td>作者</td>
<td><input name="author" type="text" id="author" size="20"></td>
</tr>
<tr>
<td>内容</td>
<td><textarea name="content" cols="50" rows="10" id="content"></td>
</tr>
</table>
<p align="center">
<input type="submit" value="Submit">
<input type="reset" value="Reset">





原文链接:https://www.f2er.com/php/29265.html
phpxmlxmlxmlxmlxmlxmlxml实例实例实例留言本

猜你在找的PHP相关文章