PHP fprintf() Function
The fprintf() function writes a formatted string to the specified output stream. This function formats a string for the specified output stream (file or database).
Syntax
fprintf(stream,format,arg1,arg2,arg++)
| Parameter | Description |
|---|---|
| stream | (Required) Specify the string to write/output the string. |
| format | (Required) Specifies formatting for strings and variables within them.
|
| arg1 | (Required) Argument to insert into first % character of format string. |
| arg2 | (Optional) Argument to insert into second % character of format string. |
| arg++ | (Optional) Argument to insert at the third,fourth,etc. % character in the format string. |
Example
<?php $name = "Ram"; $age = 25; $file = fopen("sample.txt","w"); echo fprintf($file,"%s age is %u",$name,$age); ?>
Output
14
Output text will be written to the file "sample.txt"
Ram age is 25