Oihana PHP

padStart.php

Table of Contents

Functions

padStart()  : string
Pads a UTF-8 string on the left (start) to a certain length using a specified padding string.

Functions

padStart()

Pads a UTF-8 string on the left (start) to a certain length using a specified padding string.

padStart(string|null $source, int $size, string $pad) : string

If the source string is null, it is treated as an empty string. The padding uses grapheme clusters to correctly handle multibyte characters.

Parameters
$source : string|null

The input string or null.

$size : int

Desired length after padding (in grapheme clusters).

$pad : string

The string to use for padding (cannot be empty).

Tags
throws
InvalidArgumentException

If the padding string is empty or invalid UTF-8.

example
use function oihana\core\strings\padStart;

echo padStart('hello', 10, '☺');  // Outputs: "☺☺☺☺☺hello"
echo padStart(null, 5, '*');      // Outputs: "*****"
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

The left-padded string.


        
On this page

Search results