Tutorialsplane

PHP str_pad function


PHP str_pad function : Is used to pad a string to new length with another string. This function basically pads the string to the left, right or both side of the string with a string. It accepts the string as input parameter and returns the padded string with new length. We are going to explain the str_pad function with example and demo.


PHP str_pad function Syntax

The Syntax for the str_pad is given below-

PHP str_pad function Syntax

str_pad(string,length,pad_str,pad_type);

Parameters

The Input parameters are –

Output

Returns the padded string.

Technical Requirements

Technical requirements are –

PHP Version : 4.01

PHP str_pad function Example

Here is very basic example of str_pad function-

PHP str_pad function Example:

$string = "Welcome to Tutorialsplane.";
$paddedString = str_pad($string,30,'*',STR_PAD_RIGHT);
echo $paddedString;

Try it »

If you run the above example it will produce output like this –

PHP String Functions