How to use ltrim in PHP

In this article I will explain how the ltrim() function can be used in PHP.
  • 1254

ltrim() function in PHP

  • The ltrim() function removes white spaces or other predefined character from the left side of a string.
  • The ltrim() function returns a string with whitespace

Syntax

ltrim(string,charlist)

Parameter

  • string string is required parameter. It determine check to string.
  • charlist charlist is optional parameter. it's determine for characters to remove from the string. If omitted, all of the following characters are removed:
    • "\0" - NULL
    • "\t" - tab
    • "\n" - new line
    • "\x0B" - vertical tab
    • "\r" - carriage return
    • " " - ordinary white space

Example

The following example show to how the ltrim() function can be used in PHP.

<html>

<body>

<h3 style="color: blueviolet;">ltrim() function example in PHP</h3>

    <?php

    $string1="C-sharpcorner.com ";

    $string2="\t\tC-sharpcorner.com";

    $string3="\t\tC-sharpcorner.com\x0A";

    $string4="Welcome to user";

    $trimmed_text=ltrim($string1);

    var_dump($trimmed_text);

    echo '<br>';

    $trimmed_text=ltrim($string2);

    var_dump($trimmed_text);

    echo '<br>';

    $trimmed_text=ltrim($string3);

    var_dump($trimmed_text);

    echo '<br>';

    $trimmed_text=ltrim($string1,'C-');

    var_dump($trimmed_text);

    echo '<br>';

    $trimmed_text=ltrim($string4,"Wel");

    var_dump($trimmed_text);

    ?>

</body>

</html>

 

Output

ltrim-php.gif
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.