共計 457 個字符,預計需要花費 2 分鐘才能閱讀完成。
要使用 PHP 讀取文件內容,可以使用 file_get_contents()
函數或 fopen()
和fread()
函數的組合。
使用 file_get_contents()
函數:
$fileContent = file_get_contents('file.txt');
echo $fileContent;
這將會讀取 file.txt
文件的內容,并將其輸出到瀏覽器上。
使用 fopen()
和fread()
函數:
$handle = fopen('file.txt', 'r');
if ($handle) {$fileContent = fread($handle, filesize('file.txt'));
fclose($handle);
echo $fileContent;
}
這將會打開 file.txt
文件,讀取其內容,并將其輸出到瀏覽器上。然后,關閉文件句柄。
注意:以上代碼中的 file.txt
是文件的路徑,你需要根據實際情況進行替換。
丸趣 TV 網 – 提供最優質的資源集合!
正文完