代碼執行個體:
php 檔案統計人數代碼
$countfile = "num.txt";
//定義計數器寫入的檔案是目前的目錄下count.txt,然後我們應當測試該檔案能否開啟
if (($fp = fopen($countfile, "r ")) == false) { //用讀寫入模式開啟檔案,若不能開啟就退出
printf ("開啟檔案 %s 失敗!",$countfile);
exit;
}
else
{
//如果檔案能夠正常開啟,就讀入檔案中的資料,假設是1
$count = fread ($fp,10);
//讀取10位元據
$count = $count 1;
fclose ($fp);
//關閉當前檔案
$fp = fopen($countfile, "w ");
//以覆蓋模式開啟檔案
fwrite ($fp,$count);
//寫入加1後的新資料
fclose ($fp);
//並關閉檔案
}
//$count轉換為圖片模式的代碼
$fp = fopen ($countfile, "r"); //以唯讀模式開啟檔案
$array_count = 1; //定義一個表示數組元素位置的變數,下面要用
while (! feof($fp)) {
$current_number = fgetc($fp);
$counter_array[$array_count] = $current_number;
$array_elements = count ($counter_array);
$array_count = $array_count 1;
}
//顯示代碼
echo ("
歡迎您,第");
for ($array_id = 1;$array_id < $array_elements; $array_id) {
echo ("");
}
echo ("位客人 |
");
?>
http://www.bkjia.com/PHPjc/486222.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486222.htmlTechArticle代碼執行個體 : HTML HEAD TITLEphp 檔案統計人數代碼/TITLE /HEAD BODY ?PHP $countfile = "num.txt"; //定義計數器寫入的檔案是目前的目錄下count.txt,然後我們應...