The printf() function displays a formatted string from one or more arguments.
Bạn đang xem: Php string printf() function
(PHP 4 và above)
printf(format ,arg1, arg2, arg3....)Parameter:
|format||Each conversion specification starts with a single percent sign (%) & ends with the following conversion characters.% - returns a percent sign.b - the argumentis treated as aninteger & display it as a binary number. C - the argument is treated as an integer & display it as a an ASCII value. D - the argument is treated as an integer và display as a signed decimal number. E - the argument is treated as scientific notation (e.g. 1.2e+2).E - the argument treated as scientific notation (e.g.1.2E+2).u - the argument is treated as an integer, and display as an unsigned decimal number. F- the argument is treated as a float, & display as a floating-point number. (local aware)F - the argument is treated as a float, và display as a floating-point number (non-locale aware).g - shorter of %e & %f. G - shorter of %E & %f. O- the argumentis treated as aninteger, anddisplay as anoctal number.s - the argument is treated as string và display as a string.x - the argument is treated as an integer and display as a hexadecimal number (with lowercase letters). X - the argument is treated as an integer & display as a hexadecimal number (with uppercase letters). Optional specification : Sign specifier : display a sign (+ or -) in front a number. By default, a - sign is used in front of a number if it is negative. Padding character : default character is space. An alternate paddingcharacter can bespecified by prefixingit with a single quote.Alignment specifier. : - character makes the alignment left-justified. The mặc định is right justified.Width specifier : An integer number specifies the width of the field.Precision specifier : The argument specifies how many decimal number should be displayed for floating numbers. When using this specifier on a string, it acts as a cutoff point, setting a maximum character limit to lớn the string.||Required||String|
|arg1||The argument lớn be added as the first %-sign in the formatted string.||Required||Mixed|
|arg2, arg3....||These arguments will be added as second %, third % etc. In the formatted string.||Optional||Mixed|
*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.
Returns the length of the outputted string.
Value Type: Integer.
Hello, we are learning the 12th chapter of PHP.View the example in the browser
PHP Function Reference
Previous: printNext: quoted_printable_ decode
PHP: Tips of the Day
PHP: Extract numbers from a string
$str = "In My Cart : 11 12 items";preg_match_all("!d+!", $str, $matches);print_r($matches);