本文介紹的是fopen()函數(shù),php是腳本語言,在實際使用過程中,我們可能需要讀取一些文件,獲取其中的內(nèi)容,這時候我們就可以是使用fopen()這個函數(shù),本文就帶大家一起來看一看。首先來看一看fopen()的語法
fopen ( string $filename , string $mode , bool $use_include_path = false , resource $context = ? )
$filename:要打開的文件或 URL。
$mode:參數(shù)指定了所要求到該流的訪問類型
$use_include_path:如果也需要在include_path中搜尋文件的話,可以將設(shè)為 '1' 或 true。
$context:對上下文內(nèi)容的支持
返回值:成功時返回文件指針資源,如果打開失敗,本函數(shù)返回 false。
代碼實例:
<?php $file=fopen("test.txt","r"); $user=array(); $i=0; //輸出文本中所有的行,直到文件結(jié)束為止。 while(! feof($file)) { $user[$i]= fgets($file);//fgets()函數(shù)從文件指針中讀取一行 $i++; } fclose($file); print_r($user); ?>
輸出:
Array ( [0] => zztuku.com )