PHP 8 reference · String Functions
PHP ltrim() Function
Remove whitespace or other chosen characters from the start (left side) of a string only.
PHP 8 Since 4.0
Syntax
ltrim(string $string, string $characters = " \n\r\t\v\x00"): string
Parameters
| Parameter | Description |
|---|---|
string |
The input string. |
characters optional |
The characters to strip. Default: " \n\r\t\v\x00" |
Return value
The string without leading characters.
Examples
<?php
var_dump(ltrim(" indented"));
echo ltrim("0004200", "0"), "\n";
Output
string(8) "indented" 4200
<?php
$path = "/users/42";
echo ltrim($path, "/"), "\n";
Output
users/42
Version history
| Version | Change |
|---|---|
| PHP 4.0 | Added |
In other languages
str.lstrip()· Pythonstring.trimStart()· JavaScript
Related
trim()· Remove whitespace (or other characters you choose) from both ends of a string. Spaces inside the string are kept.rtrim()· Remove whitespace or other chosen characters from the end (right side) of a string. chop() is an alias.- PHP Strings · tutorial