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 is required. Specifies the string to be filled.
Length is 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 is optional. The specified string for filling. The default value is blank.
Pad_type is 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
<? Php
$ Str = "http://www.jb51.net ";
Echo str_pad ($ str, 30 ,".");
?>
Output:
Http://www.jb51.net ........
Example 2
<? Php
$ Str = "http://www.jb51.net ";
Echo str_pad ($ str, 30, ".", STR_PAD_LEFT );
?>
Output:
...... Http://www.jb51.net
Example 3
<? Php
$ Str = "http://www.jb51.net ";
Echo str_pad ($ str, 30, ".:", STR_PAD_BOTH );
?>
Output:
..: Http://www.jb51.net .:.: