str_pad() function in php

str_pad() is a built-in PHP function that pads a string to a certain length with another string. It takes three arguments:

  1. The input string to be padded.
  2. The length of the resulting padded string.
  3. The string to use for padding (optional, defaults to space character).

The function returns the padded string.

Here's an example usage:


$input = "hello";
$padded = str_pad($input, 10, "-");
echo $padded; // Output: "hello-----"

In this example, the input string "hello" is padded with "-" characters to a length of 10. The resulting padded string is "hello-----".

Comments

Leave a Reply