ltrim
Removes whitespace or given characters from the start of a string.
Syntax
ltrim(string $string, string $characters = " \n\r\t\v\0"): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The source string. |
| $characters | string | Optional. Which characters to remove. |
Return value
stringThe string without the extra characters on the left.
Examples
Spaces on the left:
<?php
echo '[' . ltrim(' text ') . ']';Output:
[text ]Leading zeros:
<?php
echo ltrim('000742', '0');Output:
742Notes
The second argument is a set of characters, not a substring: ltrim('abcabc', 'ab') removes every leading a and b.
See also
In the tutorial
- Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.