Javatpoint Logo
Javatpoint Logo

PHP string str_pad() Function

The str_pad() is in-built PHP function which is use to pad a string to a certain length. It returns input string padded on the left, right both sides to the specified function.

Syntax:

Parameter Description Required/Optional
String Specify the string. Required
Length Specify the new string length. Required
Pad_string Specify the string for padding. Optional
Pad_type Specify what side to pad the string.
Following Value:
  • STR_PAD_BOTH
  • STR_PAD_LEFT
  • STR_PAD_RIGHT
Optional

Note 1: The pad-string may be reduced if the padding character can't be divided by the pad_string's length.

Note 2: If the pad_type is not specified then it assumed as STR_PAD_RIGHT.

Example 1

Output:

Your string isHello Javatpoint
By using str_pad() function;Hello Javatpoint.....

Example 2

Output:

Your string is:Javatpoint
By using str_pad() function:Javatpoint

Example 3

Output:

Your string isHello Javatpoint
By using str_pad() function:.....Hello Javatpoint

Example 4

Output:

Your string is: Javatpoint
By using str_pad() function: Javatpoint............

Example 5

Output:

Your string isHello Javatpoint
By using str_pad() function:..Hello Javatpoint..

Next TopicPHP String





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA