PHP檔案操作之留言板的實現

2021-08-31 19:20:22 字數 1301 閱讀 6060

一、引導頁

"center"

>

/h1>

<?php

#設定時區

date_default_timezone_set

('prc');

#讀取檔案內容

@$string

=file_get_contents

('message.txt');

if(!empty

($string))

$content

}時間為:"

.date

('y-m-d h:i:s'

,$time).

"";echo""

;}}?>

#顯示提交表單

"write.php" method=

"post"

>

使用者名稱:"text" name=

"username"

/>

>

"content"

>

<

/textarea>

>

"submit" value=

"提交"

>

<

/form>

<

/div>

二、檔案寫入頁面
<?php

$filename

="message.txt"

;#以追加寫入模式開啟檔案

$fp=

fopen

($filename

,'a');

#提交時間

$time

=time()

;#使用者名稱

$username

=trim

($_post

['username'])

;$content

=trim

($_post

['content'])

;#將一行組裝起來,資料之間用&#分隔

#行與行之間用&^分隔

$string

=$username

."&#"

.$content

."&#"

.$time

."&^"

;#將資料寫入檔案

fwrite

($fp

,$string);

#關閉檔案

fclose

($fp);

#回到引導頁

header

('location:index.php'

);

php製作留言板的題 PHP如何實現留言板功能

首先建立訊息表,其主要欄位有傳送者的名稱,訊息內容,以及訊息傳送時間 sql create table guanhui message id int 10 not null auto increment comment 訊息id sender varchar 60 not null comment ...

PHP檔案操作及例項 留言板

一 檔案操作函式 1.建立檔案 touch php bool touch string filename int time time int atime 2.複製檔案 copy php yyy.php 3.移動或重新命名 rename php yyy.php 4.刪除檔案 unlink php 5....

php學習之留言板

在對php語法有一定了解之後開始,這是第乙個php練手專案,涵蓋的知識有 root addmess.php delmess.php index.php show.php commom view head.html common lyfile.php css bootstrap.min.css dat...