Php printf
From w3cyberlearnings
Contents |
PHP function printf
This function writes a formatted string to output.
Syntax printf
- format: string product according to the format.
- arg1: argument to be inserted at the first % sign
- arg2: argument to be inserted at the second % sign
- arg++: argument to be inserted at the third
printf(format,arg1,arg2,arg3,++);
format
- % - returns a percent sign.
- b - is an integer and display it as a binary number.
- c - is an integer and display it as a ASCII value.
- d - is an integer and display as a signed decimal number.
- e - is scientific notation with lowercase letter e(e.g. 1.2e+2).
- E - is scientific notation with capital letter E(e.g.1.2E+2).
- u - is an integer, and display as an unsigned decimal number.
- f- is a float, and display as a floating-point number. (local aware)
- F - is a float, and display as a floating-point number (non-locale aware).
- g - is shorter of %e and %f.
- G - is shorter of %E and %f.
- o - is an integer, and display as an octal number.
- s - is string and display as a string.
- x - is an integer and display as a hexadecimal number (with lowercase letters).
- X - is an integer and display as a hexadecimal number (with uppercase letters).
Example 1
<?php $name="Johny"; $salary=70000; printf("%s is making %u per year",$name,$salary); ?>
Output
Johny is making 70000 per year