Use the PHP function sprintf () to format strings. Syntax: stringsprintf (stringformat, mixed [args]...); return value: string function type: data processing PHP function sprintf () is used to format strings. The format parameter is the conversion format.Syntax: string sprintf (string format, mixed [args]...);
Return value: string
Function type: data processing
The PHP function sprintf () is used to format strings. The format parameter is the conversion format, starting with the percent sign % to the conversion character. The format of the conversion includes
Fill in the blanks. If the value is 0, it indicates that the space is set to 0; if the value is 0, it indicates that the space is placed.
Alignment. The default value is right-aligned, and the negative number table is left-aligned.
Field width. Minimum width.
Precision. The number of digits after the decimal point.
For the sprintf () type of the PHP function, see the following table % to print the percentage symbol without conversion.
The integer B is converted into binary.
The c integer is converted to the corresponding ASCII character.
D integer to decimal place.
F times the precision number to the floating point number.
O integer to octal.
The s integer is converted into a string.
Convert an integer to a lowercase hexadecimal value.
Convert X to uppercase hexadecimal.
Example of using PHP function sprintf ()
-
- $ Money1 = 68.75;
- $ Money2 = 54.35;
- $ Money = $ money1 + $ money2;
- // At this time, the variable $ money value is "123.1 ";
- $ Formatted = sprintf ("% 01.2f", $ money );
- // At this time, the variable $ formatted value is "123.10"
- ?>
Optional string sprintf (string format, mixed [args]...); return value: string function type: data processing PHP function sprintf () is used to format the string. The format parameter is the conversion format...