This function returns a string with whitespace stripped from the beginning of str. Without the second parameter, ltrim()
will strip these characters:
Syntax:
1 | ltrim ( string $str [, string $character_mask ] ) : string |
Example #1 Usage example of ltrim()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?php $text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A"; $hello = "Hello World"; var_dump($text, $binary, $hello); print "\n"; $trimmed = ltrim($text); var_dump($trimmed); $trimmed = ltrim($text, " \t."); var_dump($trimmed); $trimmed = ltrim($hello, "Hdle"); var_dump($trimmed); // trim the ASCII control characters at the beginning of $binary // (from 0 to 31 inclusive) $clean = ltrim($binary, "\x00..\x1F"); var_dump($clean); ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.