PHP fputs() Function
In this chapter you will learn:
- Definition for PHP fputs() Function
- Syntax for PHP fputs() Function
- Parameter for PHP fputs() Function
- Return for PHP fputs() Function
- Example - Write string to a file
Definition
The fputs() writes to an open file.
The fputs() function is an alias of the fwrite() function.
Syntax
PHP fputs() Function has the following syntax.
fputs(file,string,length)
Parameter
Parameter | Is Required | Description |
---|---|---|
file | Required. | Open file to write to |
string | Required. | String to write to the open file |
length | Optional. | Maximum number of bytes to write |
Return
This function returns the number of bytes written on success, or FALSE on failure.
Example
<?php//from ja v a2s. co m
$file = fopen("test.txt","w");
echo fputs($file,"Hello World from java2s.com!");
fclose($file);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP fread() Function
- Syntax for PHP fread() Function
- Parameter for PHP fread() Function
- Return for PHP fread() Function
- Example - reads from a file
- Example - Read 10 bytes from file
- Example - Read entire file
Home » PHP Tutorial » PHP File Functions