Home > Article > Backend Development > Application of PHP sprintf() function (definition and usage)_PHP tutorial
sprintf(format,arg1,arg2,arg++)
参数 | 描述 |
---|---|
format | 必需。转换格式。 |
arg1 | 必需。规定插到 format 字符串中第一个 % 符号处的参数。 |
arg2 | 可选。规定插到 format 字符串中第二个 % 符号处的参数。 |
arg++ | 可选。规定插到 format 字符串中第三、四等等 % 符号处的参数。 |
The parameter format is the conversion format, starting with the percent sign ("%") and ending with the conversion character. Possible format values below:
%% - Returns percent symbol
%b - Binary number
%c - Character according to ASCII value
%d - Signed decimal Number
%e - continuous notation (such as 1.5e+3)
%u - unsigned decimal number
%f - floating point number (local settings aware)
%F - floating point number ( not local settings aware)
%o - octal number
%s - string
%x - hexadecimal number (lower case letters)
%X - hexadecimal number (upper case letters) )
arg1, arg2, ++ and other parameters will be inserted into the main string at the percent sign (%) symbol. This function is executed step by step. At the first % sign, insert arg1, at the second % sign, insert arg2, and so on
Tips and Notes
Note: If there are more % signs than arg arguments, you must Use placeholders. The placeholder is inserted after the % symbol and consists of a number and "$". See example 3.
Example
Example 1