PHP utility Function sprintf () detailed

Source: Internet
Author: User
Tags sprintf

1. Format

sprintf (Format, arg1, arg2, Arg3,..) writes the formatted string to the variable, and the bold font is the required parameter.

2. Description

Substitutions are performed incrementally, in order of the parameters, but if the% symbol is more than the number of arguments, the utility placeholder (consisting of numbers and \$) is applied, as an example:

sprintf("With 2 decimals: %1\$.2f<br />With no decimals: %1\$u",$number); Echo $txt;? >

Output:

With 2 decimals:123.00 with no decimals:123

3. Available values in the format parameter:
  • Percent-return percentage symbol
  • %b-Binary number
  • %c-Characters in accordance with ASCII values
  • %d-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 number (not local settings aware)
  • %o-Eight binary number
  • %s-String
  • %x-16 binary number (lowercase letters)
  • %x-16 decimal digits (uppercase letters)

Official explanations See: http://www.w3school.com.cn/php/func_string_sprintf.asp

PHP utility Function sprintf () detailed

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.