Definition and usage
The Str_pad () function fills a string with the specified length.
Grammar
Str_pad (string,length,pad_string,pad_type) parameter description
string is required. Specifies the string to populate.
Length required. Specifies the length of the new string. If the value is less than the length of the original string, no action is made.
Pad_string is optional. Specifies the string to use for padding. The default is blank.
Pad_type is optional. Specify the padding string over there.
Possible values:
Str_pad_both-Fills the two ends 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. This is the default.
Example 1
$str = "Http://www.jb51.net";
Echo Str_pad ($STR, 30, ".");
?>
Output:
Http://www.jb51.net .....
Example 2
$str = "Http://www.jb51.net";
Echo Str_pad ($str, ".", Str_pad_left);
?>
Output:
..... http://www.jb51.net
Example 3
$str = "Http://www.jb51.net";
Echo Str_pad ($str, ".:", Str_pad_both);
?>
Output:
.:.: Http://www.jb51.net.:.:
The above describes the PHP intercept string and zero-complement Str_pad function, including the content, I hope the PHP tutorial interested in a friend helpful.