what is the syntax of the RTRIM() function in php?
rtrim(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 RTRIM() function
Examples 1. In this example, we remove characters from the right side of a string.
<?php
$str = "Hello World! ";
echo "Without rtrim: " . $str;
echo "<br>";
echo "With rtrim: " . rtrim($str);
?>
Examples 2. In this example, we remove whitespaces from the right side of a string.
<?php
$str = "Hello World!\n\n\n";
echo "Without rtrim: " . $str;
echo "<br>";
echo "With rtrim: " . rtrim($str);
?>
Examples 3. In this example, we remove newlines (\n) from the right side of a string.
<?php
$str = "Hello World!\n\n\n";
echo "Without rtrim: " . $str;
echo "<br>";
echo "With rtrim: " . rtrim($str);
?>