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!