str_pad() function pads string to length pad_length with a specified characters : str_pad « String « PHP






str_pad() function pads string to length pad_length with a specified characters

 
Its syntax is: string str_pad (string input, int pad_length [, string pad_string [, int pad_type]])

If pad_string is not specified, string will be padded with blank spaces. 

pad_type may be assigned STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH

This example shows how to pad a string using str_pad() defaults:
<?
$food = "salad";
print str_pad ($food, 5);    
?>
  
  








Related examples in the same category

1.str_pad-2.php
2.str_pad.php
3.string str_pad ( string input, int length [, string padding [, int type]] )
4.Make use of str_pad()'s optional parameters
5.STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH:
6.There is an optional third parameter to str_pad( ) that lets you set the padding character to use
7.Using left space padding
8.Using left zero padding