What is the syntax of the LTRIM() function in php?
ltrim(string,charlist)
Parameter | Description |
---|---|
string | Required. Specifies the string to check |
charlist | Optional. Specifies which characters to remove from the string. If omitted, all of the following characters are removed:”\0″ – NULL”\t” – tab”\n” – new line”\x0B” – vertical tab”\r” – carriage return” ” – ordinary white space |
examples of the LTRIM() function
Example 1. In this example, remove characters from the left side of a string.
<?php
$str = "Hello World!";
echo $str . "<br>";
echo ltrim($str,"Hello");
?>
Example 2. In this example, we remove whitespaces from the left side of a string.
<?php
$str = " Hello World!";
echo "Without ltrim: " . $str;
echo "<br>";
echo "With ltrim: " . ltrim($str);
?>
Example 3. In this example, we remove newlines (\n) from the left side of a string.
<?php
$str = "\n\n\nHello World!";
echo "Without ltrim: " . $str;
echo "<br>";
echo "With ltrim: " . ltrim($str);
?>