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

The function of printf function in php and the introduction of each parameter

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "the function of printf function in php and the introduction of various parameters". In daily operation, I believe that many people have doubts about the function of printf function and the introduction of various parameters in php. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "the function of printf function in php and the introduction of various parameters". Next, please follow the editor to study!

1. The printf () function outputs the formatted string.

2. The arg1, arg2, arg++ parameters will be 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. The placeholder is inserted after the% symbol and consists of a number and "\ $". See example 2.

Printf () syntax:

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

Parameters.

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. )

-(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 required. 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.

Example

At this point, the study of "the function of printf function and the introduction of parameters in php" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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