Searching...
Sunday 7 October 2012

Php Read And Write Functions

9:35 pm

Php Read And Write Functions

Php Read And Write Functions :

fread():  the fread() reads form an open file. The function will stop at the end of the file or when it reaches the specified length, which ever comes first. This function returns the read string, or FALSE on failure.
 Fread(file res, length);
<?php
@$fp = fopen("alpha.txt","r");
//$str = fread($fp,  filesize("india.txt"));
$str = fread($fp,11);
echo $str;
?>
OutPut:
ABCDEFGHIJK
Fwrite():  this function writes from an open file. The function returns the number of bytes written, or false on failure.
Fwrite(file handle , string[,length]);
<?php
$file = fopen("alpha.txt","w");
$n = fwrite($file,"hello world.testing !!",5);
echo "no.of chars written=".$n;
fclose($file);
?>
OutPut:
no.of chars written=5

0 comments:

Post a Comment