Computer >> Computer tutorials >  >> Programming >> PHP

rtrim() function in PHP


The rtrim() function is used to remove the white spaces from end of the string.

Syntax

rtrim(str, charlist)

Parameters

  • str − The string to check

  • charlist − Specifies which characters to remove from the string. If this parameter isn’t included, then, all of the below given characters are removed −

    • "\0" - NULL

    • "\t" - tab

    • "\n" - new line

    • "\x0B" - vertical tab

    • "\r" - carriage return

    • " " - ordinary white space

Return

The rtrim() function returns the modified string.

Example

The following is an example −

<?php
   $str = "Welcome to our website! ";
   echo "Applying rtrim(): " . rtrim($str);
?>

Output

The following is the output −

Applying rtrim(): Welcome to our website!

Example

Let us see another example −

<?php
   $str = "Welcome to our website! \n\n\n\n\n\n ";
   echo "Applying rtrim(): " . rtrim($str);
?>

Output

The following is the output −

Applying rtrim(): Welcome to our website!