Introduction to PHP Str_pad function usage _php tips

Source: Internet
Author: User
Grammar
Str_pad (String,length,pad_string,pad_type)
Parameter description
String required. Specify the string to be populated.
Length required. Specify the length of the new string. If the value is less than the length of the original string, no action is made.
Pad_string Optional. A string that is specified for use in padding. Default is blank.
Pad_type Optional. Specify the side of the padding string.
Possible values:
Str_pad_both-fills the ends of the string. If it is not an even number, an extra padding is obtained on the right.
Str_pad_left-fills to the left of the string.
Str_pad_right-fills to the right of the string. This is the default.

Example 1
<?PHP$STR = "Hello world"; Echo Str_pad ($str, 20, ".");? > Output:
Hello world ....
Example 2
<?PHP$STR = "Hello world"; Echo Str_pad ($str, ".", Str_pad_left);? > Output:
......... Hello World
Example 3
<?PHP$STR = "Hello world"; Echo Str_pad ($str, ".:", Str_pad_both);? > Output:
.:.: Hello World.:.:.

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.