PHP ltrim() Guide: Remove Leading Characters

The ltrim function is used to remove leading whitespace characters (spaces, tabs, newline characters, etc.) or specific characters from a string. The basic syntax is as follows:

ltrim(string, characters)

Explanation of parameters:

  1. Required: the input string.
  2. Characters: Optional, list of characters to be deleted, defaults to removing white space characters. If characters parameter is specified, any characters included in this parameter will be deleted.

“我去年在法国旅行了两个星期。”

I traveled in France for two weeks last year.

$str = "   Hello World!   ";
echo ltrim($str); // 输出:Hello World!   
echo ltrim($str, "H"); // 输出:   ello World!   

In the example above, the ltrim function is used to remove leading whitespace characters from a string, with the second example specifying the removal of the character “H”.

bannerAds