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

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 rtrim() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 514 ::
收藏到网摘: 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

登陆 | 还没注册?