Definition and Usage
定义和用法
The ltrim() function will remove whitespaces or other predefined character from the left side of a string.
ltrim()函数的作用是:去除字符串左端的空白(或其它字符)。
Syntax
语法
Parameter参数 | Description描述 |
string | Required. Specifies the string to check 必要参数。指定字符串对象 |
charlist | Optional. Specifies which characters to remove from the string. If omitted, all of the following characters are removed: 可选参数。指定需要从指定的字符串中删掉那些字符。如果忽略该参数,那么下列所有的字符将都被删除: - "" - NULL
"" – NULL(空值) - "t" - tab
"t" – tab(制表符) - "n" - new line
"n" –new line(新行) - "x0B" - vertical tab
"x0B" – vertical tab(垂直制表符) - "r" - carriage return
"r" –carriage return(回车) - " " - ordinary white space
" " –ordinary white space(空格) |
Example 1
案例1
<html>
<body>
<?php
$str = " Hello World!";
echo "Without ltrim: " . $str;
echo "<br />";
echo "With ltrim: " . ltrim($str);
?>
<body>
<html> |
The browser output of the code above will be:
上述代码在浏览器中的显示结果如下:
Without ltrim: Hello World!
With ltrim: Hello World! |
If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中选择“查看源文件”,你将会看到下面的HTML数据流:
<html>
<body>
Without ltrim: Hello World!<br />With ltrim: Hello World!
</body>
</html> |
Example 2
案例2
<?php
$str = "rnHello World!";
echo "Without ltrim: " . $str;
echo "<br />";
echo "With ltrim: " . ltrim($str);
?> |
The browser output of the code above will be:
上述代码在浏览器中的显示结果如下:
Without ltrim: Hello World!
With ltrim: Hello World! |
If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中选择“查看源文件”,你将会看到下面的HTML数据流:
<html>
<body>
Without ltrim:
Hello World!<br />With ltrim: Hello World!
</body>
</html> |