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

    • "
      " - 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 −

 Live Demo

<?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 −

 Live Demo

<?php
   $str = "Welcome to our website! 





";    echo "Applying rtrim(): " . rtrim($str); ?>

Output

The following is the output −

Applying rtrim(): Welcome to our website!

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Dec-2019

112 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements