Complete PHP String Reference
The fprintf() function writes a formatted string to a specified output stream (example: file or database).
The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string. This function works "step-by-step". At the first % sign, arg1 is inserted, at the second % sign, arg2 is inserted, etc.
The fprintf() function returns the length of the written string.
| Parameter | Description |
|---|---|
| stream | Required. Specifies where to write/output the string |
| format | Required. Specifies the string and how to format the
variables in it. Possible format values:
Additional format values. These are placed between the % and the letter (example %.2f):
Note: If multiple additional format values are used, they must be in the same order as above. |
| arg1 | Required. The argument to be inserted at the first %-sign in the format string |
| arg2 | Optional. The argument to be inserted at the second %-sign in the format string |
| arg++ | Optional. The argument to be inserted at the third, fourth, etc. %-sign in the format string |
Note: If there are more % signs than arguments, you must use placeholders. A placeholder is inserted after the % sign, and consists of the argument- number and "\$". See example three.
Tip: Related functions: printf(), sprintf(), vfprintf(), vprintf(), and vsprintf().
The output of the code above will be:
The following text will be written to the file "test.txt":
The following text will be written to the file "test.txt":
Use of placeholders:
The following text will be written to the file "test.txt":
Complete PHP String Reference
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $7.95/mo SEO Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| Download XML Editor |
| FREE Website BUILDER |
| Free Website Templates Free CSS Templates |
| Make Your Own Website |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|