English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP ltrim() Function Usage and Example

   PHP String Character String Functions Manual

    The ltrim() function is used to remove whitespace characters (or other characters) from the beginning of the string.

Syntax

string ltrim ( string $str[, string $character_mask] )

Definition and Usage

It is used to remove spaces or other specified characters from the beginning of the string

Related Functions:

  • rtrim() - Remove whitespace characters or other predefined characters from the end of the string.

  • trim() - Remove whitespace characters or other predefined characters from both sides of the string.

Return Value

 This function returns a string with the leading whitespace characters of str removed. If the second parameter is not used, ltrim() only removes the following characters:

  • "\0" - NULL

  • "\t" - Tab

  • "\n" - Newline

  • "\x0B" - Vertical Tab

  • "\r" - Enter

  • " " - Space

Parameter

Serial NumberParameters and Description
1

str

Input String

2

character_mask

You can also specify the characters you want to remove through the parameter character_mask. Simply list all the characters you want to remove. Use .. to specify a range of characters.

Online Example

Try the following example

<?php
   $str = "  www.oldtoolbag.com! ";
   
   echo $str . "<br>";
   echo ltrim($str,"simply easy learning");
?>
Test and See‹/›

Output Result

www.oldtoolbag.com!
www.oldtoolbag.com!

PHP String Character String Functions Manual