Definition and usage
The Str_pad () function fills the string with a new length.
Grammar
Str_pad (String,length,pad_string,pad_type)
| Parameters |
Description |
| String |
Necessary. Specify the string to be populated. |
| Length |
Necessary. Specify the new string length. If the value is less than the original length of the string, no action is made. |
| Pad_string |
Optional. A string that is specified for use in padding. Default is blank. |
| Pad_type |
Optional. Specify which side of the string to fill.
Possible values: Str_pad_both-fills the sides of the string. If it is not an even number, an extra padding is obtained on the right. Str_pad_left-fills the left side of the string. Str_pad_right-fills the right side of the string. Default. |
1:
To the left of the fill string:
<?php
$str = "Hello World";
Echo Str_pad ($str, ".", str_pad_left);
? >
2:
To fill the sides of a string:
<?php
$str = "Hello World";
Echo Str_pad ($str, ".:", str_pad_both);
? >