Hướng dẫn dùng printf hex trong PHP
Tác dụng của hàm printf()The Show This function takes a special format string and then any number of other arguments, which will be formatted and spliced into the specified places in the format string to generate the result. Related functions: The following table summarizes the technical details of this function.
SyntaxThe basic syntax of the printf(format, arg1, arg2, argN); The following example shows the
Note: Every character in the format string will be printed literally, except the % character and characters that immediately follow it. The % character indicates the beginning of a conversion specification, which specifies how to print the arguments that follow the format string. Tip: The ParametersThe
Conversion Specification SyntaxThis section describes the syntax of conversion specification in the format string in detail. A conversion specification begins with a percent symbol (%). You must include a conversion specification for each argument that is passed to the Alternatively, you can use the argument number followed by a dollar sign (i.e. A conversion specification typically has the following syntax:
argnumAn integer followed by a dollar sign $, to specify which number argument to treat in the conversion. flagsThe flags consist of one or more of the following characters:
widthAn integer that indicates how many characters (minimum) this conversion should result in. precisionA period (.) followed by an integer who's meaning depends on the specifier:
If the period is specified without an explicit value for precision, 0 is assumed. specifierA single character indicating how the type of the argument should be interpreted.
More ExamplesHere're some more examples showing how The following example shows how to apply multiple conversion specifications to the same argument.
Tip: If the format string is enclosed in double-quotes (""), you need to escape the dollar sign after argnum with a backslash character (\), like this The following example shows how to format the same number with and without decimal points.
By default, each conversion specification will be replaced by the formatted argument in the order they are listed inside the function. But, you can swap arguments inside the format string using argnum.
Tip: If the order of the placeholders or conversion specifications in the format string does not match the order of the arguments listed inside the function. You can use argnum to easily indicate which arguments the placeholders refer to and leave the function code as is. The following example demonstrates the use of various format specifiers for different types of data.
The following example shows how to format a string in different ways using s specifier.
Bài viết này đã giúp ích cho bạn? |