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

PHP
PHP 介绍
PHP 安装
PHP 语法
PHP 变量
PHP操作符
PHP If...Else
PHP Switch
PHP 数组
PHP 循环
PHP 函数
PHP 表单
PHP $_GET
PHP $_POST
PHP Date
PHP Include
PHP 文件处理
PHP 文件上传
PHP Cookies
PHP Sessions
PHP 发送邮件

PHP 中的 rtrim() 函数


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

Definition and Usage
定义和用法

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

Syntax
语法

rtrim(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 rtrim: " . $str;
echo "<br />";
echo "With rtrim: " . rtrim($str);
?>
<body>
<html>

The browser output of the code above will be:
上述代码将输出下面的结果:

Without rtrim: Hello World!
With rtrim: Hello World!

If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中的选择“查看源文件”,你将看到下面的HTML代码:

<html>
<body>
Without rtrim: Hello World! <br />With rtrim: Hello World!
</body>
</html>


Example 2
案例2

<?php
$str = "Hello World!rn";
echo "Without rtrim: " . $str;
echo "<br />";
echo "With rtrim: " . rtrim($str);
?>

The browser output of the code above will be:
上述代码将输出下面的结果:

Without rtrim: Hello World!
With rtrim: Hello World!

If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中的选择“查看源文件”,你将看到下面的HTML代码:

<html>
<body>
Without rtrim: Hello World!
<br />With rtrim: Hello World!
</body>
</html>

评论 (0) All

登陆 | 还没注册?