- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
fprintf() function in PHP
The fprintf() function is used to write a formatted string to a stream
Syntax
fprintf (stream, format, argument1, argument2, ... )
Parameters
stream − Where to write/output the string
format − Specifies the string and how to format the variables in it.
The following are the possible format values −
%% − Returns a percent sign
%b − Binary number
%c − The character according to the ASCII value
%d − Signed decimal number (negative, zero or positive)
%e − Scientific notation using a lowercase (e.g. 1.2e+2)
%E − Scientific notation using a uppercase (e.g. 1.2E+2)
%u − Unsigned decimal number (equal to or greather than zero)
%f − Floating-point number (local settings aware)
%F − Floating-point number (not local settings aware)
%g − shorter of %e and %f
%G − shorter of %E and %f
%o − Octal number
%s − String
%x − Hexadecimal number (lowercase letters)
%X − Hexadecimal number (uppercase letters)
argument1 − The argument to be inserted at the first %-sign in the format string.
argument2 − The argument to be inserted at the second %-sign in the format string.
Return
The fprintf() function returns the length of the string written.
Example
The following is an example −
<?php $input = 123; $file = fopen("sample.txt","r"); fprintf($file,"%f",$input); ?>
Output
123.000000
To Continue Learning Please Login
Login with Google