How does php intercept a string and fill it with the str_pad () function definition and usage str_pad () function to fill the string with the specified length. The str_pad (string, length, pad_string, pad_type) parameter describes how php intercepts a string and completes the str_pad () function with zero padding.
Definition and usage
The str_pad () function fills the string with the specified length.
Syntax
str_pad(string,length,pad_string,pad_type)
Parameter 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 length of the original string, no operation is performed. |
Pad_string |
Optional. The specified string for filling. The default value is blank. |
Pad_type |
Optional. Specify the other side of the string to be filled. Possible values:
- STR_PAD_BOTH-fill in the two ends of the string. If it is not an even number, the right side will receive additional filling.
- STR_PAD_LEFT-fill in the left side of the string.
- STR_PAD_RIGHT-fill in the string to the right. This is the default one.
|
Example 1
$ Str = "http://www.my400800.cn ";
Echo str_pad ($ str, 30 ,".");
?>
Output:
Http://www.my400800.cn ........
Example 2
$ Str = "http://www.my400800.cn ";
Echo str_pad ($ str, 30, ".", STR_PAD_LEFT );
?>
Output:
...... Http://www.my400800.cn
Example 3
$ Str = "http://www.my400800.cn ";
Echo str_pad ($ str, 30, ".:", STR_PAD_BOTH );
?>
Output:
.:.:http://www.my400800.cn.:.: