sprintf
(PHP3, PHP4)
sprintf---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; Returns a formatted string
Syntax: string sprintf (string format [, mixed args ...])
Description:
Returns a string, according to the format of the formatted string.
The format string is made up of 0 (zero) or some commands, and normal characters (not including%) are copied directly to the result, which applies to sprintf () and printf ().
The specifications for each conversion are composed of these elements, in the following sequence:
The non-essential option specifies padding, indicating what characters are used to fill the result into the appropriate string length, which can be a blank character or 0 (character 0), which is preset to be padded with blanks. To replace a padding character, you can specify it by preceding the first word with a single quotation mark ('), referring to the following example.
Non-required options specify alignment to indicate whether the result should be left-aligned or right-aligned, the preset is right-aligned, and character-can be used to align it to the left.
The Not-required option specifies the width, indicating how many (or least) characters the transformation will produce.
Non-required options specify precision, which indicates that to display to the decimal point, this option has no effect on the type other than floating-point numbers, and another function Number_format () helps to format the number.
Refers to the shape of the state to describe the parameters of the form, the possible types are:
%-percent character, no arguments required
B-treats the argument as an integer, and the result is a binary value
C-treats the argument as an integer and the result is a character of this ASCII value
D-treats the argument as an integer, and the result is a value of 10 decimal
F-treats the parameter as a floating-point number, and the result is a floating-point number
O-Treats the argument as an integer and the result is an octal value
S-treats both parameters and results as strings
X-treats the argument as an integer and results in a value of 16 (lowercase letters)
X-treats the argument as an integer and results in a value of 16 (uppercase letters)
Example:
<?php
$isodate = sprintf ("%04d-%02d-%02d", $year, $month, $day);
?>
Example:
<?php
$money 1 = 68.75;
$money 2 = 54.35;
$money = $money 1 + $money 2;
echo $money would output "123.1";
$formatted = sprintf ("%01.2f", $money);
echo $formatted would output "123.10"
?>
Reference: printf () sscanf () fscanf () Number_format ()