PHP for character formatting

Source: Internet
Author: User
In PHP development we may encounter a line of words with double quotation marks to make that line of words into a string, and if there are other characters in a line of words, and so on, we use double quotation marks or single quotation marks are very prone to errors, then we are today to talk about how the PHP character formatting it!

Fortunately, our PHP function can be directly used with the PHP sprintf () function

printf//  Output formatted string sprintf ()//function writes a formatted string to a variable.

The parameters used by the PHP sprintf () function are as follows:

%//return percent symbol%B//binary number%c//character%d per 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 decimal number%s//string%x//16 decimal (lowercase)%x//16 decimal number (capital letter)

Code Case :

<?php$str = "Hello"; $number = 123; $txt = sprintf ("%s World").  Number%d ", $STR, $number); Echo $txt;? >

Code Results :

Hello World.  Number 123

Very easy to understand, we look at more, and then directly write some, you will find really convenient Oh!

Related recommendations:

PHP Format Code Related 10 Tutorial Summary

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.