乙個簡單的PHP入門源程式

2021-04-17 08:04:34 字數 1493 閱讀 7722

php" name=list scrolling=auto>

php" name=post scrolling=no>

本聊天室需使用頁框,您的瀏覽器無法使用

程式中以 frame 帶出二支 php 程式,建議將它們放在同一目錄之中,例如 /chatroom,以便日後維護。另外,為了 list.php 及 post.php 可以使用相同的變數,下例將共通的變路路徑放在 env.inc 中,可以將它放在 /chatroom 或是 web 伺服器 (如 apache) 的 php include 設定路徑中。

<?php

// 檔名: post.php

require("env.inc");

if (($chatuser!="") and ($chattext!=""))

?>

程式先檢查是否有輸入字串,若無匿名及發言內容字串則顯示發言的表單 (form),若有資料則將字串及當時時間存入檔案中 (利用 unix 的轉向指令)。當然,為了防止錯誤,先檢查是否有檔案可存檔,若沒有則先 touch 該檔,例中的檔案就是 /tmp/abc。

php_self; ?>">

<?

// 檔名: list.php

require("env.inc");

if (!file_exists($chatfile))

$uniqfile=$tempdir.uniqid(rand());

$shellcmd="/usr/bin/tail -50 ".$chatfile. " > ".$uniqfile;

passthru($shellcmd);

$chatfilearray=file($uniqfile);

$j=count($chatfilearray);

for ($i=1; $i<=$j; $i++)

unlink($uniqfile);

?>

"; exit;

} $uniqfile=$tempdir.uniqid(rand());

$shellcmd="/usr/bin/tail -50 ".$chatfile. " > ".$uniqfile;

passthru($shellcmd);

程式先檢查有沒有使用者傳送聊天內容的檔案 /tmp/abc,若沒有就顯示尚未開張,等使用者送聊天內容。若已有聊天資料,就抓出最後五十筆,在在另外的檔案中準備顯示。

$chatfilearray=file($uniqfile);

$j=count($chatfilearray);

for ($i=1; $i<=$j; $i++)

unlink($uniqfile);

將檔案讀入陣列變數 $chatfilearray 中,並以最後的資料最先顯示的方式送給瀏覽器端,當然可以使用對陣列排序的方法,但確定一定時最後存入的資料在最後面,將它排序實在很浪費 cpu 時間,因此就從最後 echo 到最前面的資料。使用完成還要用 unlink() 指令,將臨時檔殺掉。

編寫乙個桌面鬧鐘源程式

clock.c include include include include include include define x a,b,c x a cos b c pi 180.0 pi 2 midx define y a,b,c y a sin b c pi 180.0 pi 2 midy de...

乙個簡單的verlig程式 乙個簡單C程式的介紹

我們前面學了c語言的一些理論知識,今天通過乙個簡單的程式先來看一看c語言程式是什麼樣子。然後再對程式中的 進行介紹。這個語句的功能是進行有關的預處理操作。include稱為檔案包含命令,後面尖括號的內容稱為標頭檔案或首檔案。此處指包含stdio.h系統標頭檔案,在下面主函式中使用的printf 函式...

放乙個小工具的源程式

小工具乙個,很少,功能很簡單.新建c winform工程,主窗體 如下 using system using system.drawing using system.collections using system.componentmodel using system.windows.forms ...