Home  >  Article  >  Backend Development  >  ltrim() function in PHP

ltrim() function in PHP

WBOY
WBOYforward
2023-08-20 22:21:271756browse

ltrim() function in PHP

#ltrim() function is used to remove spaces or other characters from the beginning of a string.

Syntax

ltrim(str, charlist)

Parameters

  • str − The string to be checked

  • charlist − Specifies the characters to be removed from the string. If the argument is missing, all the following characters

    • ##"\0" − NULL

    • "\ t" − Tab character

    • "

      "

      − Line break character

    • "\x0B" − Vertical tab character

    • "\r" − Carriage return character

    • " " − Ordinary spaces

Return value

ltrim() function returns the modified string .

Example

The following is an example−

Live Demo

<?php
$s = " Welcome!";
echo "Without ltrim = " . $s;
echo "<br>";
echo "With ltrim = " . ltrim($s);
?>

Output

Without ltrim = Welcome!
With ltrim = Welcome!

Example

The following is an example −

Live Demo

<?php
$string = " website";
echo "Welcome to the ".ltrim($string);
?>

Output

Welcome to the website

The above is the detailed content of ltrim() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete