Home >>PHP String Functions >PHP ltrim() Function
The PHP ltrim() function is used to removes whitespaces or other characters from the left side of the given input string. It is a predefined function of PHP. This function accepts two parameters out of which only one parameter is required and the other one is optional.
Syntax:-
ltrim($string, $charlist);
Parameter | Description |
---|---|
String | This is a required parameter. This parameter specify the string to be checked. |
charlist | This is an optional parameter. This parameter specify the character to be removed from the given string.
|
Here is an example of ltrim() function in PHP:
<html> <body> <?php $str = "!!!!!!!!!!!!!!!!!!!!!!! PHPTPOINT !"; echo "Without ltrim: ".$str . "<br>"; echo "With ltrim: " . ltrim($str,"!"); ?> </body> </html>
Here is an another example of ltrim() function in PHP:
<html> <body> <?php $str = " PHPTPOINT"; echo "Without ltrim: " . $str; echo "<br>"; echo "With ltrim: " . ltrim($str); ?> </body> </html>
Here is an another example of ltrim() function in PHP:
<html> <body> <?php $str = "\n\nPHPTPOINT"; echo "Without ltrim: " . $str; echo "<br>"; echo "With ltrim: " . ltrim($str); ?> </body> </html>