Nov 02
PHP 檔案處理
讀檔:
1.fopen
範例:
<?php $handle = fopen("open_file.txt", "r"); if( $handle === FALSE) { echo "Open File Fail" . "<br>"; } else { echo "Open File Success" . "<br>"; while (!feof($handle)) { $current_line = fgets($handle); echo $current_line . "<br>"; } } ?>
2.file_get_contents
範例:
<?php $handle = file_get_contents('open_file.txt'); echo $handle; ?>
=========================================================
寫檔:
1.fwrite
<?php $handle = fopen('open_file.txt', 'w'); fwrite($handle, "test1"); fclose($fp); ?>
ps:fwrite 是沒有加換行字元,如果要換行必須加上 \n 處理
2.file_put_contents
<?php $handle = 'open_file.txt'; $current_line = "line1\n"; file_put_contents($handle, $current_line); ?>
source: PHP:檔案處理 @ 拉不拉多的夢幻世界 :: 痞客邦 PIXNET ::
溫故知新
載入中…
歷史上的今天..
- 寫程式的生活? - 2008







最新回應