Str_pad () uses another string to populate the string with the specified length.
string str_pad ( string $input, int $pad_length
[, string $pad_string=" "[, int $pad_type=STR_PAD_RIGHT]])
Copy the code
Parameters to describe
input
Input a string.
pad_length
If the value of pad_length is negative, less than or equal to the length of the input string, no padding will occur.
pad_string
If the length of the padding character is not divisible by pad_string, then pad_string may be shortened.
pad_type
The possible values of the optional pad_type parameter are STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified, it is assumed to be STR_PAD_RIGHT.
The return value:
This function returns the result of input being filled to a specified length from the left, right, or both ends. If the optional pad_string argument is not specified, input will be filled with space characters, otherwise it will be filled with pad_string to the specified length
Example:
<? php $input="Alien"; echo str_pad($input,10); / / output "Alien" echo str_pad ($input, 10, "_", STR_PAD_BOTH); // output "__Alien___" echo str_pad($input,6,"___"); / / output Alien_ ""Copy the code