ltrim()
The ltrim()
function accepts a string as its parameter, removes whitespace from the left side of that string, and then returns it.
Optionally, ltrim()
can accept a second parameter containing specific characters to remove from the left side of a target string.
Syntax
ltrim($string, $characters);
The $string
parameter gives the function a target string to remove whitespace or specific characters from.
The $characters
parameter is an optional string that specifies characters the function should remove. ltrim()
will start at the left side of the string and remove any characters that match the ones provided in the $characters
argument until it finds one that does not match.
Codebyte Example
The following example demonstrates the ltrim()
function with both one and two arguments.
The second argument, in the second call of the function, removed the characters H
, e
, y
, o
, and the single space. It left the rest of the string starting from the character M
because it wasn’t instructed by the second argument to remove that character.
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.