Learn How To Use Itrim Function With Example In PHP

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

The ltrim()  function removes whitespace and other predefined characters from left sides of a string.

PHP ltrim Function with example

Syntax of ltrim() function and Usage.

ltrim(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 ltrim() function.
echo ltrim($str,"HeT!");

Example(1)
<?php
    $str = "Hello World! welcome to BAJARANGISOFT";
    echo   "<h4>$str </h4>";
    echo   ltrim($str,"HeT!");
?>

Complete Code of  ltrim() Function:
<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP left 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 ltrim() Function</h1>
    </div>
    <br>
    <h2>The ltrim()  function removes whitespace and other predefined characters from left sides of a string.</h2>
    <div class="well">
        <?php
            $str = "Hello World! welcome to BAJARANGISOFT";
            echo   "<h4>$str </h4>";
            echo   ltrim($str,"HeT!");
        ?>
    </div>
    <br>
</div>
</body>
</html>





 

Related Post