PHP formatted string function instance usage

Source: Internet
Author: User
In PHP, there are many formatting methods for strings. the formatting types can be divided into string formatting and numeric character formatting. the formatting of numeric characters is the most commonly used. In PHP, there are many formatting methods for strings. the formatting types can be divided into string formatting and numeric character formatting. the formatting of numeric characters is the most commonly used.

The following describes in detail the numeric character formatting function number_format.

The number_format () function definition is used to format numeric strings.

The syntax format is as follows:

number_format(number,decimals,decimalpoint,separator)

Parameter description: the number_format () function can have one, two, or four parameters, but not three. If there is only one parameter number, after the number is formatted, the value after the novel vertex is removed, and the 3rd-bit number is separated by commas (,). if there are two parameters, number is formatted to decimals. decimalpoint is used to replace the decimal point (.), separator is used to replace the comma (,) separated by 3rd digits (,).

Use the number_format () function to format the specified numeric string. the sample code is as follows:

 "; Echo number_format ($ number, 2); // output the formatted numeric string echo"
"; $ Number1 = 223344.556677; echo number_format ($ number1, 2, '.', '.'); // output the formatted numeric string?>

Output result:

6,667

6,666.88

223.344.56

Brief introduction to string case-insensitive conversion functions

Four string case-insensitive conversion functions are provided in PHP. they all have only one optional string parameter, that is, the string to be converted. Here we will give a brief introduction to using these functions to perform case-insensitive conversion. The strtoupper () function is used to convert all the given strings to uppercase letters. the strtolower () function is used to convert all the given strings to lowercase letters. the ucfirst () function () converts the first letter of a given string to uppercase, and the rest of the characters remain unchanged. ucwords () is used to convert the first letter of all words in a given string separated by spaces to uppercase. The following code is used for these functions:

 

The output result is as follows:

Lamp is composed of linux, apache, mysql and php

Lamp is conposed of linux, APACHE, MYSQL AND PHP

Lamp is composed of Linux, Apache, MySQL and PHP

Lamp Is Composed Of Linux, Apache, MySQL And PHP

These functions only work in the way they describe. to ensure that the first letter of a string is an upper-case letter, while the rest are lower-case letters, you need to use the appropriate method. As follows:

 

Output: Lamp is composed of linux, apache, mysql and php




The above describes the usage of the PHP formatted string function instance. For more information, see other related articles in the first PHP community!

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.