The ltrim() function is used to strip whitespace or other characters from the beginning of a string.
Syntax
ltrim(str, charlist)
Parameters
str − The string to be checked
charlist − It specifies which characters to remove from the string. If the parameters are missed, then all of the following characters are removed
"\0" − NULL
"\t" − tab
"\n" − new line
"\x0B" − vertical tab
"\r" − carriage return
" " − ordinary white space
Return
The ltrim() function returns the modified string.
Example
The following is an example −
<?php $s = " Welcome!"; echo "Without ltrim = " . $s; echo "<br>"; echo "With ltrim = " . ltrim($s); ?>
Output
Without ltrim = Welcome! With ltrim = Welcome!
Example
The following is an example −
<?php $string = " website"; echo "Welcome to the ".ltrim($string); ?>
Output
Welcome to the website