php xml實(shí)例 留言本
更新時(shí)間:2009年03月20日 00:15:17 作者:
實(shí)例學(xué)習(xí)制作xml留言本代碼。
復(fù)制代碼 代碼如下:
<?php
//打開用于存儲(chǔ)留言的XML文件
$guestbook = simplexml_load_file('DB/guestbook.xml');
foreach($guestbook->thread as $th) //循環(huán)讀取XML數(shù)據(jù)中的每一個(gè)thread標(biāo)簽
{
echo "<B>標(biāo)題:</B>".$th->title."<BR>";
echo "<B>作者:</B>".$th->author."<BR>";
echo "<B>內(nèi)容:</B><PRE>".$th->content."</PRE>";
echo "<HR>";
}
?>
復(fù)制代碼 代碼如下:
<?php
$guestbook = new DomDocument(); //創(chuàng)建一個(gè)新的DOM對象
$guestbook->load('DB/guestbook.xml'); //讀取XML數(shù)據(jù)
$threads = $guestbook->documentElement; //獲得XML結(jié)構(gòu)的根
//創(chuàng)建一個(gè)新thread節(jié)點(diǎn)
$thread = $guestbook->createElement('thread');
$threads->appendChild($thread);
//在新的thread節(jié)點(diǎn)上創(chuàng)建title標(biāo)簽
$title = $guestbook->createElement('title');
$title->appendChild($guestbook->createTextNode($_POST['title']));
$thread->appendChild($title);
//在新的thread節(jié)點(diǎn)上創(chuàng)建author標(biāo)簽
$author = $guestbook->createElement('author');
$author->appendChild($guestbook->createTextNode($_POST['author']));
$thread->appendChild($author);
//在新的thread節(jié)點(diǎn)上創(chuàng)建content標(biāo)簽
$content = $guestbook->createElement('content');
$content->appendChild($guestbook->createTextNode($_POST['content']));
$thread->appendChild($content);
//將XML數(shù)據(jù)寫入文件
$fp = fopen("DB/guestbook.xml", "w");
if(fwrite($fp, $guestbook->saveXML()))
echo "留言提交成功";
else
echo "留言提交失敗";
fclose($fp);
?>
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>發(fā)表新的留言</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<H1><p align="center">發(fā)表新的留言</p></H1>
<form name="form1" method="post" action="Post.php">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>標(biāo)題</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>內(nèi)容</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>
相關(guān)文章
laravel框架之?dāng)?shù)據(jù)庫查出來的對象實(shí)現(xiàn)轉(zhuǎn)化為數(shù)組
今天小編就為大家分享一篇laravel框架之?dāng)?shù)據(jù)庫查出來的對象實(shí)現(xiàn)轉(zhuǎn)化為數(shù)組,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10php is_executable判斷給定文件名是否可執(zhí)行實(shí)例
這篇文章主要介紹了php is_executable判斷給定文件名是否可執(zhí)行實(shí)例的相關(guān)資料,需要的朋友可以參考下2016-09-09thinkPHP基于ajax實(shí)現(xiàn)的菜單與分頁示例
這篇文章主要介紹了thinkPHP基于ajax實(shí)現(xiàn)的菜單與分頁,結(jié)合實(shí)例形式分析了thinkPHP基于ajax無刷新交互實(shí)現(xiàn)菜單及分頁功能的相關(guān)技巧與注意事項(xiàng),需要的朋友可以參考下2016-07-07使用PHP連接數(shù)據(jù)庫_實(shí)現(xiàn)用戶數(shù)據(jù)的增刪改查的整體操作示例
下面小編就為大家?guī)硪黄褂肞HP連接數(shù)據(jù)庫_實(shí)現(xiàn)用戶數(shù)據(jù)的增刪改查的整體操作示例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09PHP實(shí)現(xiàn)獲取FLV文件的時(shí)間
這篇文章主要介紹了PHP實(shí)現(xiàn)獲取FLV文件的時(shí)間,本文直接給出實(shí)現(xiàn)代碼和使用方法,需要的朋友可以參考下2015-02-02php中的filesystem文件系統(tǒng)函數(shù)介紹及使用示例
這篇文章主要介紹了php中的filesystem文件系統(tǒng)函數(shù)使用示例,需要的朋友可以參考下2014-02-02