Monday, 29 September 2014

ltrim in PHP

PHP ltrim() function is utilized to removed whitespace or other predefined character from left side of a string.

Syntax:
ltrim(string,charlist)

Parameters Description:
"\0" – NULL
"\t" – tab
"\n" – new line
"\x0B" – vertical tab
"\r" – carriage return
" " – ordinary white space

Example:

string : Required. Defines the input string.

charlist : Optional. Indicates which character to remove.

If not then all of the following characters will be removed:


<?php
$str_name = "\n\nToday is Monday";
echo "Without ltrim : ". $str_name;
echo "<br />";
echo "With ltrim : ". ltrim($str_name);
?>
Browser output will be:
Without ltrim : Today is Monday 
With ltrim : Today is Monday
If You Select "View Source" in the browser window, you will see the following HTML :

<html>
<body>
Without ltrim : Today is Monday
<br />
With ltrim : Today is Monday
</body>
</html>

0 comments:

Post a Comment