Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

ltrim

Removes whitespace or given characters from the start of a string.

Syntax

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

Parameters

ParameterTypeDescription
$stringstringThe source string.
$charactersstringOptional. 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:

742

Notes

The second argument is a set of characters, not a substring: ltrim('abcabc', 'ab') removes every leading a and b.

See also

  • trim — Removes whitespace and other characters from both ends of a string.
  • rtrim — Removes whitespace or given characters from the end of a string.

In the tutorial

  • Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.

Thanks for reading!

Donate to the site — we work hard for you.