PHP rtrim() 函数
移除字符串右侧的字符:
<?php
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!");
?>
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!");
?>
定义和用法
rtrim() 函数移除字符串右侧的空白字符或其他预定义字符。
相关函数:
实例 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!
版权声明:本页面内容旨在传播知识,为用户自行发布,若有侵权等问题请及时与本网联系,我们将第一时间处理。E-mail:284563525@qq.com