PHP rtrim Function

What is rtrim Function and how it is used in string?


The rtrim function is used to strip whitespaces or other characters from the end of a string in PHP.



the above syntax "string" specifies the strings to be stripped, "charlist" specifies the charatcers to be stripped as the user can specify from the following characters " -NULL", "t - tab","n - new line","x0B - vertical tab", "r - carriage return", " " - ordinary white space".

Example :

$str = "Hiox India!
$str2 = "Web Our World";
echo "With rtrim: " .rtrim($str);
echo $str2;
echo "<br>";
echo "Without rtrim: " . $str;
echo $str2;


With rtrim: Hiox India!Web Our World
Without rtrim: Hiox India! Web Our World

In the above example the spaces on the right of "Hiox india" is stripped and the result is displayed, in the second statement the result is displayed with a space in between the strings.

PHP Topics

Ask Questions

Ask Question