PHP ltrim() Function (original) (raw)

Last Updated : 11 Jul, 2025

The ltrim() function is a built-in function in PHP which removes whitespaces or other characters (if specified) from the left side of a string.Syntax:

ltrim( string,string, string,charlist )

Parameters: The function ltrim() accepts two parameters as shown in the above syntax. Out of these two parameters, one is mandatory while the other one is optional. They are discussed in details below:

Return Value: Returns the modified string. Examples:

Input : $string = " Geeks for Geeks" Output : Geeks for Geeks

Input : string="!!!((!!))GeeksforGeeks",string = "!!! (( !!)) Geeks for Geeks", string="!!!((!!))GeeksforGeeks",charlist = "! ()" Output : Geeks for Geeks

Below programs illustrate the ltrim() function :Program 1 : This program shows the use of ltrim() function without any specified list of characters to be removed.

php `

`

Output:

Contribute to Geeks for Geeks

Program 2: This program shows the use of ltrim() function with a specified list of characters to be removed.

php `

`

Output:

Geeks for Geeks

Reference: https://www.php.net/manual/en/function.ltrim.php