This article mainly introduces PHP in Str_pad () function usage, more detailed analysis of PHP str_pad () function function, parameter meaning and specific use method, the need for friends can refer to the following
The examples in this article describe the usage of functions in PHP str_pad()
. Share to everyone for your reference, as follows:
str_pad()
The function fills the string with a new length .
Grammar:
str_pad(string,ength,pad_string,pad_type);
Parameter list:
parameter |
description |
string |
required. Specifies the string to populate. |
length |
required. Specifies the new string length. If the value is less than the original length of the string, no action is made. |
pad_string |
optional. Specifies the string to use for padding. The default is blank. |
Pad_type |
Optional. Specifies which side of the string to fill. Possible values: Str_pad_both-fills the sides of the string. If it is not an even number, the right side gets an extra fill. Str_pad_left-fills the left side of the string. Str_pad_right-fills the right side of the string. Default. |
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*************************