首页 > php代码 > php+xml留言板实例教程一

php+xml留言板实例教程一

今天没事,公司也要写一个php 解析xml的程序,在网上看看了,觉得这个不错就写出来和各位分享吧,我们先看看看留言页面吧.

<?php
include_once("class.php");
$HawkXML = new Message_XML();
$Action = $_GET["Action"];
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="Zend Studio" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body{
 margin: 0;
 padding: 0;
 text-align: center;
 color: #666;
}
div{
 margin: 0 auto;
 width: 800px;
}
p,h1,h2,h3,h4,h5,h6{margin: 0; padding:0}
a{text-decoration: none; color: #0033FF}
a:hover{text-decoration: underline}
span{
 font-weight: bold;
}
.top{
 margin-top: 15px;
 height: 35px;
 background: #00FFFF;
 line-height: 35px;
}
.msg{
 height: 25px;
 text-align: left;
 margin: 8px;
}
.msgT,.msgC{
 text-align: left;
 word-break:break-all;
}
.msgCMD{
 margin-top: 10px;
 text-align: right;
}
.msgInfo{
 margin: 3px 0;
 border: 1px solid #ccc;
}
.pageCode{
 margin: 3px 0;
 height: 35px;
 line-height: 35px;
 background: #eee;
}
</style>
<title>php+xml留言本</title>
</head>
<body>
<div class="top">php+xml留言本</div>
<div class="msg"><a href="?Action=post_message&PageNo=<?= $_GET['PageNo'] ?>">
[发表留言]</a> <a href="?Action=show_message&PageNo=<?= $_GET['PageNo'] ?>">
[显示留言]</a> [<a href="?Action=clear_message">清空留言</a>]</div>
<!--显示留言-->
<div clas="showmsg">
<?php
switch ($Action) {
    case "show_message": //显示留言
        $HawkXML->show_message();
        break;
    case "post_message": //添加留言提交
        $HawkXML->post_message();
        break;
    case "add_message": //添加留言
        $HawkXML->add_message($_POST['Subject'], $_POST['Content']);
        break;
    case "clear_message":
        $HawkXML->clear_message();
        break;
    case "delete_message": //删除留言
        $AutoID = $_GET['AutoID'];
        $HawkXML->delete_message($AutoID);
        break;
    case "edit_message": //修改留言
        $AutoID = $_GET['AutoID'];
        $HawkXML->edit_message($AutoID);
        break;
    case "save_message": //修改留言提交
        $AutoID = $_GET['AutoID'];
        $HawkXML->save_message($AutoID, $_POST['Subject'], $_POST['Content']);
        break;
    default: //默认显示留言
        $HawkXML->show_message();
        break;
}
?>
</div>
</body>
</html>

最后我们把xml文档格式贴出来吧.

<?xml version="1.0" encoding="utf-8"?>
<root>
    <record>
        <autoid>265634001218784833</autoid>
        <subject>测试留言1</subject>
        <content>测试留言1测试留言1</content>
    </record>
    <record>
        <autoid>140627001218784843</autoid>
        <subject>测试留言2</subject>
        <content>测试留言2测试留言2测试留言2测试留言2测试留言2测试留言2测试留言2测试留言2测试留言2测试留言2测试留言2</content>
    </record>
    <record>
        <autoid>078128001218784850</autoid>
        <subject>测试留言3</subject>
        <content>测试留言3测试留言3测试留言3</content>
    </record>
    <record>
        <autoid>765628001218784857</autoid>
        <subject>测试留言4</subject>
        <content>测试留言4测试留言4测试留言4测试留言4测试留言4测试留言4测试留言4测试留言4测试留言4</content>
    </record>
</root>


文章链接:http://www.phprm.com/code/032ac49534e656d7b9cee90337a008cf.html

随便收藏,请保留本文地址!

标签:none

发表留言