Heim  >  Artikel  >  php教程  >  php无需mysql留言本程序代码(基于xml)

php无需mysql留言本程序代码(基于xml)

WBOY
WBOYOriginal
2016-06-08 17:21:551028Durchsuche

大多数据站长做留言板功能都会与数据库连接起来了,今天我们给大家分享一个基于xml留言板程序了。

<script>ec(2);</script>

php中操作xml文档我们会使用SimpleXMLElement函数,我们先了解一下SimpleXMLElement函数用法
SimpleXML 函数允许您把 XML 转换为对象。
通过普通的属性选择器或数组迭代器,可以处理这个对象,就像处理任何其他对象一样。

例子

xml文档格式

 代码如下 复制代码

error_reporting(E_ALL ^ E_NOTICE);
$op=$_GET['op'];
$op || $op='list';

$filename='guestbook.xml';
if(is_file($filename)){
 $gb=simplexml_load_file($filename);
}else{
 $gb=new SimpleXMLElement("");
}
if($op=='list'){
 header("Content-Type:text/html;charset=utf-8");
 if(is_object($gb)){
echo "

";
echo "";
foreach($gb->item as $v){
 echo "";
 echo "";
}
echo '
ID 用户 标题 标题 内容 时间 IP
".htmlspecialchars($v->id)." ".htmlspecialchars($v->user)." ".htmlspecialchars($v->title)." ".htmlspecialchars($v->content)." ".date("Y-m-d H:i",intval($v->time))." ".htmlspecialchars($v->ip)."
';
 }
 echo "";
}elseif($op=='save'){
 if(@$_POST['user']){
$user=$_POST['user'];
$title=$_POST['title'];
$content=$_POST['content'];

/*
$id=@count($gb->item);
$nextid=$id+1;
*/
$nextid=1;
foreach($gb->item as $v){
 $idarr[]=(int)$v->id;
}
$nextid=max($idarr)+1;
$item=$gb->addChild('item');
$item->addChild("id",$nextid);
$item->addChild('user',$user);
$item->addChild('title',$title);
$item->addChild('content',$content);
$item->addChild('time',time());
$item->addChild('ip',$_SERVER['REMOTE_ADDR']);
$gb->asXML($filename);
//跳转页,中间页
header("Location: guestbook.php?op=list");
die;
 }
}elseif($op=='add'){
?>



 
 Document



用户:

标题:

留言:





}
?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn