★ wanayoo — archive 1999 http://www.php.net/manual/de/function.fgets.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Filesystem
Quick Reference
English version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Filesystem
* basename
* chgrp
* chmod
* chown
* clearstatcache
* copy
* delete
* dirname
* diskfreespace
* fclose
* feof
* fgetc
* fgetcsv
* fgets
* fgetss
* file
* file_exists
* fileatime
* filectime
* filegroup
* fileinode
* filemtime
* fileowner
* fileperms
* filesize
* filetype
* flock
* fopen
* fpassthru
* fputs
* fread
* fseek
* ftell
* fwrite
* set_file_buffer
* is_dir
* is_executable
* is_file
* is_link
* is_readable
* is_writeable
* link
* linkinfo
* mkdir
* pclose
* popen
* readfile
* readlink
* rename
* rewind
* rmdir
* stat
* lstat
* realpath
* symlink
* tempnam
* touch
* umask
* unlink
Manual: fgets
View the source code for this pageSearch the site



Previous page
 fgetcsv
 Updated
Sat, 12 Aug 2000
fgetss 
Next page


fgets

(PHP3 , PHP4 )

fgets --  Liest eine Zeile von der Position des Dateizeigers

Beschreibung

string fgets (int fp, int length)

Gibt eine Zeile zurück mit einer in length definierten Länge -1 Byte, welche aus der Datei von der aktuellen Position des Dateizeigers fp aus ausgelesen wird. Die Zeile endet an einem Zeilenumbruch, EOF (Ende der Datei) oder bei lenght Zeichen (Je nachdem, was eher auftritt).

Wenn ein Fehler auftritt, wird FALSE zurückgegeben.

Häufig auftretende Fehler:

Wenn Sie an die C-Semantik von fgets gewöhnt sind, sollten Sie auf die unterschiedliche Behandlung von EOF (genauer: wie EOF zurückgegeben wird) achten.

Der Datei-Zeiger fp muss gültig sein, d.h. die Datei, auf die gezeigt wird, muss zuvor mit fopen(), popen() oder fsockopen() geöffnet worden sein.

Ein einfaches Beispiel:

Beispiel 1. Eine Datei Zeile für Zeile einlesen


$fd = fopen ("/tmp/inputfile.txt", "r");
while (!feof($fd)) {
    $buffer = fgets($fd, 4096);
    echo $buffer;
}
fclose ($fd);
      

Siehe auch fread(), fopen(), popen(), fgetc() und fsockopen().


User Contributed Notes: fgets


patrickc@espider.com
13-Jan-2000 11:09
i don't know how to handle the array string:
The result of username and the string length not right~
e.g.
username : "abc "
strlen : 5
e.g. (username.txt)
abc
cde
efgh

Program :
if($myFile = fopen("username.txt","r")){
while(!feof($myFile)){
$username[]=fgets($myFile,20);
}
// Count total user number
$totaluser = count($username);
fclose($myFile);
}

Please help me~~thanks~



hellekin@imaginet.fr
22-Mar-2000 01:10
<pre>You should use :

$users = file("username.txt");
$number_of_users = sizeof($users);

fgets() returns one line as a string
while
file() returns all lines as an array.
</pre>



info@dsdi.de
28-Mar-2000 06:15
For some hosts ($mxhost) the fgets never stops, also maximum execution time is never reached:

<PRE>$fp = fsockopen ( $mxhost, 25, $errno, &$errstr, 30 );
fputs ( $fp, "HELO $SERVER_NAME\n" );
$result = fgets ( $fp, 2000 );</PRE>

Enviroment: Linux Kernel 2.2.5, php 3.0.12



yung3890@kimo.com.tw
30-Mar-2000 03:24
I have a text file ,like this :
0012345 432 12345 567
0023456 656456 234
.....
the line length is fixed .
now I use $str=fgets($fp,"text file") to read this file
But when I echo $str ,the browser can't
show the white spaces.
it looks like :
0012345 432 12345 567
0023456 656456 234
....
I hope the browser can show the white spaces.





c_sidcar@club-internet.fr
16-May-2000 08:26
fgets return a line terminated by \n in Unix
and \r\n in Windows.
It's hard to test php script on Windows before using it in Unix !!



froggywwu@hotmail.com
29-Jun-2000 06:57
I was using fgets to get one byte at a time from a file and I was using 1 for the length, e.g. fgets($fp,1). This should give you one character from the file, so I put it in a do while loop which terminates when it finds a space. Using length one does not grab one byte from the file it grabs maybe a space or something, what you need to do to grab a singe byte from a file you need to have length 2, otherwise you will cause the webserver to crash or become extrememly slow.


 About Notes


Previous page
 fgetcsv
 Updated
Sat, 12 Aug 2000
fgetss 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.