Detailed introduction to str_pad () function usage in php

Source: Internet
Author: User
This article mainly introduces the str_pad () function usage in php, and analyzes the function, parameter meaning, and usage of str_pad () function in php in detail, for more information about str_pad () function usage in php, see the next article. the Function, parameter meaning, and usage of str_pad () in php are analyzed in detail, for more information, see

This example describesstr_pad()Function usage. We will share this with you for your reference. The details are as follows:

str_pad()FunctionFill the string with a new length..

Syntax:

str_pad(string,ength,pad_string,pad_type);

Parameter list:

Parameters Description
String Required. Specifies the string to be filled.
Length Required. Specify the length of the new string. If the value is smaller than the original length of the string, no operation is performed.
Pad_string Optional. The specified string for filling. The default value is blank.
Pad_type Optional. Specifies the side of the string to be filled. Possible value: STR_PAD_BOTH-fill both sides of the string. If it is not an even number, the right side will receive additional filling. STR_PAD_LEFT-fill the left side of the string. STR_PAD_RIGHT-fill the right side of the string. Default value.


For example:

class test{ private $var; public function construct($var){ $this->var=$var; } public function test(){ $result=str_pad($this->var,30,"*"); return $result; }}$T=new test("hello");$result=$T->test();echo $result;

Output:

hello*************************

The above is a detailed description of str_pad () function usage in php. 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.