Required : If $length is less than , zero or equal to length of Input string then no padding takes place and $input_string is returned
Optional : To be used as padding. If not given blank space is used. Padding is done upto the limit.
Optinoal: Which side padding is to be added STR_PAD_RIGHT ( default ) STR_PAD_LEFT STR_PAD_BOTH
Using the string function str_pad() we can pad one input string upto some given length or pad using another string. If no second string is given then the input string is padded by blank space.
This function is useful when some data is to be formatted upto some length. We want the blank space after the input or marked with some chars like ---- . Another example is where we are displaying data in rows and wants all records to perfectly align in left and right. Here if all data are not of equal length we can pad them and keep all in one line. The extra space can be formatted as per requirement.