Home >>PHP String Functions >PHP rtrim() Function
PHP rtrim() function is used to remove whitespaces form the right end of a string. It also removes other predefined characters (if specified) from the right side of a string. This function accepts two parameters out of which, one is mandatory while the other one is optional.
Syntax:
rtrim( $string, $charlist );
Parameter | Description |
---|---|
string | This is a required parameter. This parameter contains the string to be checked. |
charlist | This is an optional parameter. This parameter defines which characters to remove from the string.
|
Here is an example of rtrim() function in PHP:
<html> <body> <?php $str = "PHP "; echo rtrim($str); echo "(no space)"; ?> </body> </html>
Here is an another example of rtrim() function in PHP:
<html> <body> <?php $str = "Everyone is Beautiful & Smart."; echo $str . "<br>"; echo rtrim($str,"& Smart."); ?> </body> </html>