Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert 1 to 01 in php

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to convert 1 to 01 in php". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In PHP, you can use the sprintf () function to convert "1" to "01", which can write a formatted string to a variable and zero in the string when the parameter is set to "d". The syntax is "sprintf (" d ", 1)".

Operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer

How to convert 1 to 01 in php

The sprintf () function writes the formatted string to a 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.

The syntax is:

Sprintf (format,arg1,arg2,arg++)

The parameters are expressed as follows:

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 you use more than one of the above format values, they must be used in the above order and cannot be disrupted.

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, fourth, and so on% symbols in the format string.

Examples are as follows:

Output result:

This is the end of the content of "how to convert 1 to 01 in php". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report