Usage analysis of sprintf () function in PHP

Source: Internet
Author: User
Tags uppercase letter
This article describes the use of PHP in the sprintf () function, the need for friends, refer to the next bar.

sprintf function

Define and use the sprintf () function to write a formatted string into a variable.

Grammar sprintf (format,arg1,arg2,arg++)

Parameter description

Format required. Conversion format. Arg1 required. Specifies the parameter that is inserted into the first% symbol in the format string. Arg2 is optional. Specifies the parameter that is inserted into the second% symbol in the format string. arg++ is optional. Specifies the parameter that is inserted into the format string third to fourth, and so on, in the% symbol.

Description

The parameters format is the converted format, starting with the percent sign ("%") to the end of the converted character. The following are the possible format values:

Percent-return percentage symbol%b-binary number%c-character%d according to ASCII value-Signed decimal number%e-sustainable counting method (e.g. 1.5e+3)%u-unsigned decimal number%F-floating point (Local settings Aware)%F-floating point (not local Settings aware)%o-eight binary number%s-string%x-16 binary (lowercase)%x-16 decimal number (uppercase letter)

Arg1, arg2, + + etc parameters will be inserted into the main string percent percent (%) Symbol. This function is executed step-by. In the first% symbol, insert arg1, insert arg2 at the second% symbol, and so on.

Hints and Comment notes: 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 a "\$".

Tip: Related functions: fprintf (), printf (), vfprintf (), vprintf (), and vsprintf ().

The above is excerpted from the PHP manual for your reference.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.