PHP » Strings » rtrim()

Syntax:
string rtrim(string s [, string remove_list])
s
The string.
remove_list
Characters to remove.

Trims whitespace off the right side of a string.

rtrim() works just as trim() but only trims off characters on the right side of the string. The new trimmed string is returned. The optional remove_list parameter can be used to specify which characters should be trimmed off.

Examples

Code:
<pre>
<?php

$s1 = rtrim("   \t  hello there   \n");
$s2 = rtrim("--- hello ---", "-");
printf("[%s]<br>[%s]", $s1, $s2);

?>
</pre>
Output:
[        hello there]
[--- hello ]
Explanation:

rtrim() is used on two strings, both with and without the use of remove_list.

See Also: