The sprintf () function is used to write a formatted string into a variable.
Definition and usage
The sprintf () function is used to write a formatted string into a variable.
Grammar
sprintf (format,arg1,arg2,arg++) parameter description
Format required. Conversion format.
Arg1 required. Specifies the parameter that is inserted into the first% symbol in the format string.
Arg2 is optional. Specifies the parameter that is inserted into the second% symbol in the format string.
arg++ is optional. Specifies the parameter that is inserted into the format string third to fourth, and so on, in the% symbol.
Description
The parameters format is the converted format, starting with the percent sign ("%") to the end of the converted character. The following possible format values are:
%%-return percent symbol
%b-binary number
%c-Characters in accordance with ASCII values
%d-Signed decimal number
%e-Sustainable counting method (e.g. 1.5e+3)
%u-Unsigned decimal number
%f-Floating point (Local settings Aware)
%f-Floating point number (not local settings aware)
%o-Eight binary number
%s-String
%x-16 decimal digits (lowercase letters)
%x-16 decimal digits (uppercase letters)
Arg1, arg2, + + etc parameters will be inserted into the main string percent percent (%) Symbol. This function is executed step-by. In the first% symbol, insert arg1, insert arg2 at the second% symbol, and so on
Hints and Notes
Note: If the% symbol is more than the arg parameter, you must use a placeholder. The placeholder is inserted after the% symbol and consists of a number and a "$". See Example 3.
Example
Example 1
The code is as follows |
Copy Code |
? |
Output:
? Hello World. Day Number 123
Example 2
The code is as follows |
Copy Code |
? |
Output:
? 123.000000
Example 3
The code is as follows |
Copy Code |
? with no decimals:%1$u ", $number); echo $txt;?> |
Output:
? With 2 decimals:123.00 with no decimals:123
Example 4
The code is as follows |
Copy Code |
? Output: ? application/pdf |
http://www.bkjia.com/PHPjc/445309.html www.bkjia.com true http://www.bkjia.com/PHPjc/445309.html techarticle The sprintf () function is used to write a formatted string into a variable. Define and use the sprintf () function to write a formatted string into a variable. Grammar sprintf (format,a ...