Learn How To Use Rtrim Function With Example In PHP

admin_img Posted By Bajarangi soft , Posted On 24-09-2020

The rtrim()  function removes whitespace and other predefined characters from right side of a string.

PHP rtrim Function with example

Syntax of rtrim() function and Usage.

rtrim(string,charlist)


Parameter Values

string -> Specifies the string to check.

charlist->Specifies which characters to remove.
            If this is not mentioned then all of the following characters will be removed:
             .   “\0” – NULL
             .   “\t” – tab
             .   “\n” – new line
             .   “\x0B” – vertical tab
             .   “\r” – carriage return
             .   ” ” – ordinary white space


Let's learn

1.Create string

$str = "Hello World! welcome to BAJARANGISOFT";


2.Print string using rtrim() function.

echo rtrim($str,"HeFT!");


Example(1)

<?php
    $str = "Hello World! welcome to BAJARANGISOFT";
    echo   "<h4>$str </h4>";
    echo   rtrim($str,"HeFT!");
?>


Complete Code of  rtrim() Function:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP right trim function</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <div class="text-center">
        <h1>PHP rtrim() Function</h1>
    </div>
    <br>
    <h2>The rtrim()  function removes whitespace and other predefined characters from right side  of a string.</h2>
    <div class="well">
        <?php
            $str = "Hello World! welcome to BAJARANGISOFT";
            echo   "<h4>$str </h4>";
            echo   rtrim($str,"HeFT!");
        ?>
    </div>
    <br>
</div>
</body>
</html>

Related Post