站长资源网络编程
php xml实例 留言本
简介复制代码 代码如下:thread as $th) //循环读取XML数据中的每一个thread标签 { e
复制代码 代码如下:
<?php
//打开用于存储留言的XML文件
$guestbook = simplexml_load_file('DB/guestbook.xml');
foreach($guestbook->thread as $th) //循环读取XML数据中的每一个thread标签
{
echo "<B>标题:</B>".$th->title."<BR>";
echo "<B>作者:</B>".$th->author."<BR>";
echo "<B>内容:</B><PRE>".$th->content."</PRE>";
echo "<HR>";
}
?>
复制代码 代码如下:
<?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);
?>
复制代码 代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>发表新的留言</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<H1><p align="center">发表新的留言</p></H1>
<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"></textarea></td>
</tr>
</table>
<p align="center">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</p>
</form>
</body>
</html>
<?php
//打开用于存储留言的XML文件
$guestbook = simplexml_load_file('DB/guestbook.xml');
foreach($guestbook->thread as $th) //循环读取XML数据中的每一个thread标签
{
echo "<B>标题:</B>".$th->title."<BR>";
echo "<B>作者:</B>".$th->author."<BR>";
echo "<B>内容:</B><PRE>".$th->content."</PRE>";
echo "<HR>";
}
?>
复制代码 代码如下:
<?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);
?>
复制代码 代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>发表新的留言</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<H1><p align="center">发表新的留言</p></H1>
<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"></textarea></td>
</tr>
</table>
<p align="center">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</p>
</form>
</body>
</html>
最新资源
- 群星《天赐的声音第五季 第5期》[320K/MP3][118
- 群星《天赐的声音第五季 第5期》[FLAC/分轨][29
- 群星《歌手2024 第3期》[320K/MP3][78.45MB]
- 群星《歌手2024 第3期》[FLAC/分轨][204.16MB]
- 群星《乘风2024 第6期》[320K/MP3][57.95MB]
- 群星《乘风2024 第6期》[FLAC/分轨][170.72MB]
- 陈立强1995-我爱你胜过这世界[福茂][WAV+CUE]
- 群星-《2014年十大发烧唱片精选HQCD》[低速原抓
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限
- 林育群.2013-BalladShow(日本版)【环球】【WAV+