当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > ltrim() 函数

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 ltrim() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 559 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The ltrim() function will remove whitespaces or other predefined character from the left side of a string.
ltrim()函数的作用是:去除字符串左端的空白(或其它字符)。

Syntax
语法

ltrim(string,charlist)

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>

评论 (0) All

登陆 | 还没注册?