The ltrim()
function removes the leading space characters or other specified characters from the left side of a string.
The image below shows a visual representation of the ltrim()
function.
ltrim(string,charsToBeRemoved)
The ltrim()
function takes two parameters:
If the value of the charsToBeRemoved is not specified, then the following characters are removed from the left side of the string:
- " " - white space
- “\t” - tab
- “\n” - new line
- “\x0B” - vertical tab
- “\r” - carriage return
- “\0” - NULL
ltrim()
removes the leading space characters or the other specified characters from the left side of a string.
The example below shows how to use ltrim()
in PHP.
<?php#single character removed from stringecho("ltrim('!educative','!'): ");echo(ltrim('!educative','!'));echo("\n");echo("ltrim('!()educative','!'): ");echo(ltrim('!()educative','!'));echo("\n");#multiple characters removed from stringecho("ltrim('!,()educative','! , ()'): ");echo(ltrim('!,()educative','! , ()'));echo("\n");#default ~ without the list of characters to be removedecho("ltrim(' educative'): ");echo(ltrim(' educative'));echo("\n");?>