frequently ask ? : Computers : Programming : Languages : PHP : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 7 people (43%) answered Yes
Recently 0 of 4 people (0%) answered Yes

Entry

How do I control the number of bytes sent to an output file in PHP?

Feb 17th, 2000 10:45
Matt Gregory, Elaine Ham, Ben Udall, http://www.php.net/manual/function.fwrite.php3


the fputs(filepointer, string, length) function is an alias to the 
fwrite function.  both of these functions take a length which determins 
the amount of data to be put to the file.
If the length parameter is not provided, fwrite stops when a NULL 
character is reached, or a (\n) is reached.  If you provide a length, 
file output will stop when the number of bytes specified has been 
printed, or when a null character is reached.
Please note that when the length parameter is provided no escape 
characters will be striped from the string before output.
//example.php3
$fp = fopen("myfile.txt", "r+");
$mystring = "It\'s a beautiful day in the neighborhood!";
fputs($fp, $mystring, sizeof($mystring));
fputs($fp, $mystring);
fputs($fp, $mystring, 4);
//data in myfile.txt:
It\'s a beautiful day in the neighborhood!
It's a beautiful day in the neighborhood!
It\'