PHP function fputs() writes string into an open file. The fputs function will stop at the end of the file or when it reaches the specified length, whichever comes first. PHP fputs function is an alias of the fwrite() function, so you can use either.
1 2 3
$file = fopen("fputs.txt", "w"); fputs($file, "PHP fputs is working..."); fclose($file);
Although in our snippet, we didn’t use all parameters available for fputs function, we should mention that fputs function has tree parameters and in following snippet, syntax is shown:
fputs($file, $string, $length);
Last parameter of fputs function is length that will determine length of written string into file. So if your string in fputs is longer than $length – it will be shorten.