Published May 1, 2023
Contribute to Docs
rtrim() function removes whitespace or other predefined characters from the right side of a string.
$stringparameter is the string from which characters are removed.
$charlistparameter specifies which characters to remove from the string. If omitted, then the following characters are removed from the right side (if applicable):
\n- new line
x0B- vertical tab
\r- carriage return
" "- space
The following example removes specified characters from the right side of a string:
<?php$str = "Hello World!\n";echo "Without rtrim: " . $str;echo "With rtrim: " . rtrim($str, "World!\n");?>
This results in the following output:
Without rtrim: Hello World!With rtrim: Hello
The following runnable example removes whitespaces from the right side of the string:
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.