PHP 教程
fgets() 函數(shù)從打開(kāi)的文件中返回一行。
fgets() 函數(shù)會(huì)在到達(dá)指定長(zhǎng)度( length - 1 )、碰到換行符、讀到文件末尾(EOF)時(shí)(以先到者為準(zhǔn)),停止返回一個(gè)新行。
如果失敗該函數(shù)返回 FALSE。
fgets(file,length)
參數(shù) | 描述 |
---|---|
file | 必需。規(guī)定要讀取的文件。 |
length | 可選。規(guī)定要讀取的字節(jié)數(shù)。默認(rèn)是 1024 字節(jié)。 |
上面的代碼將輸出:
Hello, this is a test file.
上面的代碼將輸出:
Hello, this is a test file. There are three lines here. This is the last line.