str_pad
Use another string to fill a string to a length
str_pad()
function fills the string with a new length.
Fill the right side of the string to the new length of 30 characters:
<?php $str = "Hello World" ; echo str_pad ( $str , 30 , "." ) ; ?>
Try it yourself
Fill the left side of the string:
<?php $str = "Hello World" ; echo str_pad ( $str , 30 , "." , STR_PAD_LEFT ) ; ?>
Try it yourself
Fill both sides of the string:
<?php $str = "Hello World" ; echo str_pad ( $str , 30 , ".:" , STR_PAD_BOTH ) ; ?>
Try it yourself
str_pad ( string , length , pad_string , pad_type )
parameter | describe |
---|---|
string | Required. Specifies the string to be filled. |
length | Required. Specifies the new string length. If the value is less than the original length of the string, nothing is done. |
pad_string | Optional. Specifies the string for padding. The default is blank. |
pad_type |
Optional. Specifies which side of the string to fill. Possible values:
|