PHP fread() 函數
PHP fread() 函數

定義和用法
fread() 函數讀取打開的文件。
函數會在到達指定長度或讀到文件末尾(EOF)時(以先到者為準),停止運行。
該函數返回讀取的字符串,如果失敗則返回 FALSE。
語法
string fread ( resource $handle , int $length )
參數 | 描述 |
---|---|
handle | 文件系統指針,是典型地由 fopen() 創建的 resource(資源)。 |
length | 必需。規定要讀取的最大字節數。 |
提示和注釋
提示:該函數是二進制安全的。(意思是二進制數據(如圖像)和字符數據都可以使用此函數寫入。)
實例 1
從文件中讀取 10 個字節:
<?php
$file = fopen("test.txt","r");
$contents = fread($file,"10");
fclose($file);
?>
$file = fopen("test.txt","r");
$contents = fread($file,"10");
fclose($file);
?>
實例 2
讀取整個文件:
<?php
$file = fopen("test.txt","r");
$contents = fread($file,filesize("test.txt"));
fclose($file);
?>
$file = fopen("test.txt","r");
$contents = fread($file,filesize("test.txt"));
fclose($file);
?>

相關文章
- PHP 安裝
- PHP 變量
- PHP EOF(heredoc) 使用說明
- PHP 運算符
- PHP 面向對象
- PHP 文件處理
- PHP 異常處理
- PHP JSON
- PHP array_chunk() 函數
- PHP array_diff_assoc() 函數
- PHP array_intersect_uassoc() 函數
- PHP array_reduce() 函數
- PHP array_search() 函數
- PHP array_slice() 函數
- PHP sort() 函數
- PHP 5 Directory 函數
- PHP 5 Filesystem 函數
- PHP FTP 函數
- PHP HTTP 函數
- PHP Libxml 函數