Analysis of str_pad () function usage in php, phpstr_pad
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*************************
PS: here we will provide you with a related php function table for your reference:
Php online function reference table:
Http://tools.jb51.net/table/php_fun_table