
Techknow Heights - tkhts.com
Techknow Heights - tkhts.com
Modes | Description |
---|---|
r | Read only at the beginning of the file. |
r+ | Read or Write at the beginning of the file |
w | It will create a new file if it does not exist and if exist it erase the contents of any file of this name before writing. |
w+ | Read and Write if the file doesn't exist so it will create a file of this name, and if exist it will erase the contents of any file of this name before writing. |
a | Append,use to open and write to the end of the file if exist. |
a+ | Read and Write to the end of the file if exist. |
fopen()
: This function is used to open the files in PHP. <?php $file=fopen("D:\tkhts\id.txt","r") or exit("Unable to open file!"); ?>
fclose()
:This function is used to close an open file.
<?php $file = fopen("D:\tkhts\id.txt","r"); //code executed fclose($file); ?>
feof
:This function checks end-of-file on a file pointer and takes a
filename as argument and it is used in a while loop to perform the
same task(function) on each line in a file.
while(!feof($f)) { $val=fgets($f); echo "val"; echo"end of file"; }
fgets()
:This function is used to read a single line from a file in PHP.
fgetc()
:This function is used to read a single character from a file.
<?php $f = fopen("D:\tkhts\id.txt", "r") or exit("Unable to open file!"); while(!feof($f)) { echo fgets($f). "<br>"; } fclose($f); ?>
Learn PHP from : www.tkhts.com
<?php $file=fopen("D:\tkhts\id.txt","r") or exit("Unable to open file!"); while (!feof($f)) { echo fgetc($f)."<br>"; } fclose($f); ?>
L e a r n P H P f r o m : w w w . t k h t s . c o m