In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use php sprintf". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use php sprintf.
The function php sprintf writes the formatted string to the variable. Its syntax is "sprintf (format,arg1,arg2,arg++)", and the parameter format specifies the string and how to format the variable in it.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
What is the use of php sprintf?
The sprintf () function writes the formatted string to the variable.
The arg1, arg2, + + parameters are inserted at the percent sign (%) symbol in the main string. This function is executed step by step. At the first% symbol, insert arg1, at the second% symbol, insert arg2, and so on.
Note: if the% symbol is more than the arg parameter, you must use a placeholder. Placeholders are located after the% symbol and consist of numbers and "\ $". See example 2.
Hint: related functions: printf (), vprintf (), vsprintf (), fprintf () and vfprintf ()
Fprintf () printf () vfprintf () vprintf () vsprintf ()
Grammar
Sprintf (format,arg1,arg2,arg++)
Parameter format is required. Specifies the string and how to format the variables in it.
Possible format values:
%%-returns a% sign
% b-binary number
Characters corresponding to% c-ASCII value
% d-Decimal number containing plus or minus sign (negative, 0, positive)
% e-use lowercase scientific counting (e.g. 1.2e+2)
% E-use uppercase scientific counting (e.g. 1.2E+2)
% u-Decimal number without plus or minus sign (greater than or equal to 0)
% f-floating point number (local setting)
% F-floating point number (non-local setting)
% g-shorter% e and% f
% G-shorter% E and% f
% o-Octal number
% s-string
% x-hexadecimal numbers (lowercase letters)
% X-hexadecimal number (uppercase)
The additional format value. Must be placed between% and letters (for example,% .2f):
+ (precede the number with + or-to define the positivity or negativity of the number. By default, only negative numbers are marked, positive numbers are not marked)
'(specifies what to use as a fill, with spaces by default. It must be used with the width specifier. For example:% 'x20s (filled with "x")
-(adjust variable value to the left)
[0-9] (specifies the minimum width of the variable value)
. [0-9] (specify the number of decimal places or the maximum string length)
Note: if multiple of the above format values are used, they must be used in the above order.
Arg1 is required. Specifies the parameter inserted at the first% symbol in the format string.
Arg2 is optional. Specifies the parameter inserted at the second% symbol in the format string.
Arg++ is optional. Specifies the parameters inserted at the third and fourth% symbols in the format string.
Example
Replace the percent sign (%) sign with a variable passed as a parameter:
Running result:
There are 2 million cars in Shanghai. At this point, I believe you have a deeper understanding of "how to use php sprintf". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.