国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁(yè)課程PHP fun classRead file operation

Read file operation

目錄列表

讀文件內(nèi)容

要讀取文件里的內(nèi)容,并按逐行進(jìn)行讀取有兩種方式。

1、fgets()逐行讀取文件

fgets() 函數(shù)用于從文件中逐行讀取文件。

注釋:在調(diào)用該函數(shù)之后,文件指針會(huì)移動(dòng)到下一行。

實(shí)例

下面的實(shí)例逐行讀取文件,直到文件末尾為止:

<?php
 $file = fopen("welcome.txt", "r") or exit("Unable to open file!");
 //feof()函數(shù)檢測(cè)是否已到達(dá)文件末尾(EOF)。
 while(!feof($file))
 {
 echo fgets($file). "<br>";
 }
 fclose($file);
 ?>

2、使用PHP file() 函數(shù)

file() 函數(shù)把整個(gè)文件讀入一個(gè)數(shù)組中。

數(shù)組中的每個(gè)元素都是文件中相應(yīng)的一行,包括換行符在內(nèi)。

例如:

<?php
 $arr = file("test.txt");
 print_r($arr);
?>

結(jié)果:

Array
 (
 [0] => Hello World. Testing testing!
 [1] => Another day, another line.
 [2] => If the array picks up this line,
 [3] => then is it a pickup line?
 )


哪些函數(shù)用于讀取文件的內(nèi)容?

1/2