PHP rtrim() Function


The rtrim() function is used to removes whitespace or characters from the right side of a string.

Syntax
rtrim(string,charlist)
Parameter Description
String (Required) Specify the string to check.
charlist (optional) Specify character to remove the Following characters.
  • "\0" - NULL

  • "\t" - tab

  • "\n" - new line

  • "\x0B" - vertical tab

  • "\r" - carriage return

  • " " - ordinary white space
  • Example
    <?php
        $a = "Hello World!";
        echo $a . "<br>";
        echo rtrim($a,"World!");
    ?>
    

    Output

    Hello World!
    Hello
    

    Prev Next