Php ltrim
From w3cyberlearnings
Contents |
PHP function ltrim
This function strips whitespace from the begining of a given string.
Syntax ltrim
- string: a given string to strip whitespace
- charlist (optional): List all characters that you want to be stripped.
- \0 -- NULL
- \t -- Tab
- \n -- New line
- \x0B -- vertical tab
- \r -- Carriage return
- " " -- whitespace
ltrim(string, charlist);
Example 1
<?php $str =' Good old'; echo $str; echo '<br/>'; echo ltrim($str); echo '<br/>'; echo $str; echo '<br/>'; echo ltrim($str); ?>
Output
- Display as the HTML source code.
- The first and third without using ltrim function.
- The second and last use the ltrim function.
Good old<br/>Good old<br/> Good old<br/>Good old
Example 2
<?php $str ="Hello World"; $str_trim = ltrim($str,'Hello'); echo $str; echo '<br/>'; echo $str_trim; ?>
Output
Hello World World