亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home php教程 php手冊 How to read files using feof() function in PHP

How to read files using feof() function in PHP

Oct 28, 2016 pm 03:03 PM

This article mainly introduces the method of using the feof() function to read files in PHP, compares the correct and incorrect usage in the form of examples, and explains the usage skills of the feof() function. Friends in need can refer to it

The example in this article describes how PHP uses the feof() function to read files. Share it with everyone for your reference. The specific usage is as follows:
feof is applied to PHP 4, PHP 5
-used to test whether the file pointer has reached the end of the file.
If the server does not close the connection opened by fsockopen(), feof() will wait until timeout and return TRUE. The default timeout limit is 60 seconds, this value can be changed using stream_set_timeout().
The file pointer must be valid and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).

If the passed file pointer is invalid, it may fall into an infinite loop, because EOF will not return TRUE.
Example #1 feof() using invalid file pointer Example:

<?<span style="color: #000000">php
</span><span style="color: #008000">//</span><span style="color: #008000"> 如果文件不可讀取或者不存在,fopen 函數(shù)返回 FALSE</span>
<span style="color: #800080">$file</span> = @<span style="color: #008080">fopen</span>("http://www.manongjc.com/article/1329.html", "r"<span style="color: #000000">);
</span><span style="color: #008000">//</span><span style="color: #008000"> 來自 fopen 的 FALSE 會發(fā)出一條警告信息并在這里陷入無限循環(huán). </span>
<span style="color: #0000ff">while</span> (!<span style="color: #008080">feof</span>(<span style="color: #800080">$file</span><span style="color: #000000">)) {
}
</span><span style="color: #008080">fclose</span>(<span style="color: #800080">$file</span><span style="color: #000000">);
</span>?>

Example:

<?<span style="color: #000000">php 
</span><span style="color: #800080">$file</span> = <span style="color: #008080">fopen</span>(<span style="color: #800080">$_SERVER</span>['DOCUMENT_ROOT']."/me/test.txt", "r"<span style="color: #000000">); 
</span><span style="color: #008000">//</span><span style="color: #008000"> http://www.manongjc.com/article/1328.html
//輸出文本中所有的行,直到文件結(jié)束為止。 </span>
<span style="color: #0000ff">while</span>(! <span style="color: #008080">feof</span>(<span style="color: #800080">$file</span><span style="color: #000000">)) 
{ 
</span><span style="color: #0000ff">echo</span> <span style="color: #008080">fgets</span>(<span style="color: #800080">$file</span>). "<br />"<span style="color: #000000">; 
} 
</span><span style="color: #008080">fclose</span>(<span style="color: #800080">$file</span><span style="color: #000000">); 
</span>?>

Output:
Hello, this is a test file.
There are three lines here.
This is the last line.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72