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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

ltrim(string $string, string $characters = " \n\r\t\v\x00"): string

Parameters

ParameterDescription
string The input string.
characters optional The characters to strip. Default: " \n\r\t\v\x00"

Return value

The string without leading characters.

Examples

Strip from the leftTry it yourself
<?php
var_dump(ltrim("   indented"));
echo ltrim("0004200", "0"), "\n";

Output

string(8) "indented"
4200
Remove a leading slashTry it yourself
<?php
$path = "/users/42";
echo ltrim($path, "/"), "\n";

Output

users/42

Version history

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?