日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php简单的用户留言板实现内容(1-23)

發布時間:2024/7/19 php 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php简单的用户留言板实现内容(1-23) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

靜態模版來源

可視化布局

代碼實現

<?php header('content-type:text/html;charset=utf-8'); date_default_timezone_set("Asia/Shanghai"); /*構思:建立一個文本文件,通過操作文件,寫入數據、讀取數據!file_get_contents 讀文件file_put_contents 寫文件通過serialize 產生一個可儲存的值通過unserialize 創建一個可儲存的值通過讀取值寫入值,來保存操作我們需要的值 */// 文件名: $filename = 'info.txt';// 創建保存數據的數組 $msg = []; /*['username'=>'','tit'=>'','content'=>''] */// 檢測文件是否存在,若不存在,創建文件 if( !file_exists( $filename ) ){fopen($filename,'w+'); } // 判斷文件內是否有內容 $string = file_get_contents($filename); if( strlen($string)>0 ){$msg = unserialize($string); };// 檢測變量是否設置,是否點擊提交內容了~ if ( isset( $_POST['pubMsg'] ) ){$username = $_POST['username'];$title = strip_tags($_POST['title']);$content = strip_tags($_POST['content']);// 時間'$time = time();$data = compact('username','title','content','time');// 添加到數組當中去array_push($msg,$data);$msg = serialize($msg);// 寫入數據if( file_put_contents($filename,$msg) ){echo "<script> alert('留言成功'); location.href = 'index.php';</script>";}else {echo "<script> alert('留言失敗'); location.href = 'index.php';</script>";} } ?><!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script><script type="text/javascript" src="http://apps.bdimg.com/libs/jqueryui/1.9.2/jquery-ui.min.js"></script><link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet"><script src="http://cdn.bootcss.com/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script> </head> <style>table tr:nth-child(even){background:#90EE90;} </style> <body><div class="container-fluid"><div class="row-fluid"><div class="span12"><div class="page-header"><h1>留言板-<span>V1.0</span></h1></div><div class="hero-unit"><h1>Hello!!!</h1><p>有事請留言</p><p><a rel="nofollow" class="btn btn-primary btn-large" href="#">參看更多 ?</a></p></div><!-- if(): endif;判斷是否為數組以及數組內數值是否為空--><table class="table"><?php if ( is_array($msg) && count($msg)>0 ):?><thead><tr><th>編號</th><th>用戶名</th><th>標題</th><th>內容</th><th>時間</th></tr></thead><tbody><tr class="success"><?php $i=1; foreach ($msg as $value): ?><td><?php echo $i++ ?></td><td><?php echo $value['username']; ?></td><td><?php echo $value['title']; ?></td><td><?php echo $value['content']; ?></td><td><?php echo date('Y年-m月-d日-G時-i分',$value['time']); ?></td></tr><?php endforeach;?></tr></tbody><?php endif; ?></table><form action="#" method="post"><fieldset><legend>請留言</legend><label>用戶名</label><input type="text" name="username" required /><label>標題</label><input type="text" name="title" required /><label>內容</label><textarea name="content" rows="5" cols="30" required></textarea><hr><input type="submit" class="btn btn-primary btn-lg" name="pubMsg" value="發布留言" /></fieldset></form></div></div></div> </body></html>

文件保存格式.php

轉載于:https://www.cnblogs.com/ar13/p/8335117.html

總結

以上是生活随笔為你收集整理的php简单的用户留言板实现内容(1-23)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。