PHP str_pad() Function
Example
Pad the right side of a string to a new length of 20 characters:
Run Example »
Definition and Usage
The str_pad() function pads a string to a new length.
Syntax
str_pad(
string,length,pad_string,pad_type
)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to pad. |
| length | Required. Specifies the new string length. If this value is less than the original string length, no action is taken. |
| pad_string | Optional. Specifies the string used for padding. Default is blank. |
| pad_type | Optional. Specifies which side of the string to pad.
Possible values: |
Technical Details
| Return Value: | Returns the padded string. |
|---|---|
| PHP Version: | 4.0.1+ |
More examples
Example 1
Pad the left side of a string:
Run Example »
Example 2
Pad both sides of a string:
The output is:
.:.:Hello World.:.:.
PHP String Reference Manual