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 use printf in php

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

Share

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

This article mainly introduces how to use printf in php. It is very detailed and has a certain reference value. Friends who are interested must finish it!

The function php printf outputs formatted strings, and the syntax for printf is "printf (format,arg1,arg2,arg++)", where the parameter format specifies the string and how to format the variables in it.

Operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer

What is the use of php printf?

The printf () function outputs the formatted string.

The arg1, arg2, and arg++ 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. 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.

Examples

Use the format value% f:

Output:

123.000000

Related functions: sprintf (), vprintf (), vsprintf (), fprintf () and vfprintf ()

The above is all the content of the article "how to use printf in php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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