PHP str_pad() Function: Usage, Parameters, Return Value, and Examples
The article explains PHP's str_pad() function, detailing how it pads a string to a specified length with optional padding characters and types, describes each parameter and return value, and provides multiple code examples demonstrating right, left, and both‑side padding.
str_pad() pads a string to a specified length using another string.
Parameters
input : the input string.
pad_length : desired length; if negative or less than or equal to the input length, no padding occurs.
pad_string (optional): string used for padding; if its length does not divide evenly, it may be truncated.
pad_type (optional): STR_PAD_RIGHT, STR_PAD_LEFT or STR_PAD_BOTH; default is STR_PAD_RIGHT.
Return value
The padded string, padded on the left, right, or both sides according to the specified parameters; if pad_string is omitted, spaces are used.
Examples
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.