The rtrim() function removes the trailing space characters or other specified characters from the right side of a string.
The following illustration shows a visual representation of the rtrim() function.
rtrim(string,charsToBeRemoved)
The rtrim() function takes two parameters:
If the value of
charsToBeRemovedis not specified, then the following characters are removed from the right side of a string:
- " " - white space
 - “\t” - tab
 - “\n” - new line
 - “\x0B” - vertical tab
 - “\r” - carriage return
 - “\0” - NULL
 
rtrim()returns the modified string.
The example below demonstrates how to use rtrim() in PHP:
<?php#single character removed from stringecho("rtrim('educative()','()'): ");echo(rtrim('educative()','()'));echo("\n");echo("rtrim('educative!()','()'): ");echo(rtrim('educative!()','()'));echo("\n");#multiple characters removed from stringecho("rtrim('educative!,()','! , ()'): ");echo(rtrim('educative!,()','! , ()'));echo("\n");#default ~ without the list of characters to be removedecho("rtrim('educative '): ");echo(rtrim('educative '));echo("\n");?>