PHP rtrim() 函数
PHP 教程
· 2019-01-29 20:28:23
实例
移除字符串右侧的字符:
<?php
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!");
?>
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!");
?>
定义和用法
rtrim() 函数移除字符串右侧的空白字符或其他预定义字符。
相关函数:
- ltrim() - 移除字符串左侧的空白字符或其他预定义字符。
- trim() - 移除字符串右侧的空白字符或其他预定义字符。
语法
rtrim(string,charlist)
| 参数 | 描述 |
|---|---|
| string | 必需。规定要检查的字符串。 |
| charlist | 可选。规定从字符串中删除哪些字符。如果省略该参数,则移除下列所有字符:
|
技术细节
| 返回值: | 返回已修改的字符串。 |
|---|---|
| PHP 版本: | 4+ |
| 更新日志: | 在 PHP 4.1 中,新增了 charlist 参数。 |
更多实例
实例 1
移除字符串右侧的空格:
<?php
$str = "Hello World! ";
echo "Without rtrim: " . $str;
echo "<br>";
echo "With rtrim: " . rtrim($str);
?>
$str = "Hello World! ";
echo "Without rtrim: " . $str;
echo "<br>";
echo "With rtrim: " . rtrim($str);
?>
上面代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html>
<html>
<body>
Without rtrim: Hello World! <br>With rtrim: Hello World!
</body>
</html>
<html>
<body>
Without rtrim: Hello World! <br>With rtrim: Hello World!
</body>
</html>
上面代码的浏览器输出如下:
Without rtrim: Hello World!
With rtrim: Hello World!
With rtrim: Hello World!
实例 2
移除字符串右侧的换行符(\n):
<?php
$str = "Hello World!nnn";
echo "Without rtrim: " . $str;
echo "<br>";
echo "With rtrim: " . rtrim($str);
?>
$str = "Hello World!nnn";
echo "Without rtrim: " . $str;
echo "<br>";
echo "With rtrim: " . rtrim($str);
?>
上面代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html>
<html>
<body>
Without rtrim: Hello World!
<br>With rtrim: Hello World!
</body>
</html>
<html>
<body>
Without rtrim: Hello World!
<br>With rtrim: Hello World!
</body>
</html>
上面代码的浏览器输出如下:
Without rtrim: Hello World!
With rtrim: Hello World!
With rtrim: Hello World!
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
机器学习及其应用2007
周志华 编 / 清华大学 / 2007-10 / 37.00元
机器学习是人工智能的一个核心研究领域,也是近年来计算机科学中最活跃的研究分支之一。目前,机器学习技术不仅在计算机科学的众多领域中大显身手,还成为一些交叉学科的重要支撑技术。本书邀请相关领域的专家撰文,以综述的形式介绍机器学习中一些领域的研究进展。全书共分13章,内容涉及高维数据降维、特征选择、支持向量机、聚类、强化学习、半监督学习、复杂网络、异构数据、商空间、距离度量以及机器学习在自然语言处理中的......一起来看看 《机器学习及其应用2007》 这本书的介绍吧!