PHP string printf() Function
PHP string printf() function predefined functions. It is used to output a formatted string. We can pass the arg1, arg2, arg++ parameters at percent (%) signs in the main string.
Syntax:
Parameter |
Description |
Required/Optional |
format |
Specify the string. 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)
|
Required |
arg1 |
The argument to be inserted at the first %-sign. |
Required |
arg2 |
The argument to be inserted at the second %-sign. |
Optional |
arg++ |
The argument to be inserted at the third,fourth, etc. %s sign |
optional |
Example 1
Output:
We are Learning PHP 7 form JAVATPOINT.
Example 2
Output:
Example 3
Output:
With 2 decimals: 23456.00
With no decimals: 23456
Example 4
Output:
[Hello]
[ Hello]
[Hello ]
[000Hello]
[***Hello]
[Hello PH]
|