PHP字符过滤函数去除字符串最后一个逗号(rtrim)

yipeiwu_com6年前PHP代码库

首先分别解释下,

trim过滤字符串两端,
rtrim过滤字符串尾部,=chop()
ltrim过滤字符串首部.

过滤字符串中键的咚咚就只能用str_replace咯.
举个例子说明下,

PHP代码

复制代码 代码如下:

$str = '123,333,234,';
echo rtrim($str, ',');

rtrim实例代码2

复制代码 代码如下:

<?php
$text = "\t\tThese are a few words :) ...  ";
$trimmed = rtrim($text);
// $trimmed = "\t\tThese are a few words :) ..."
$trimmed = rtrim($text, " \t.");
// $trimmed = "\t\tThese are a few words :)"
$clean = rtrim($binary, "\x00..\x1F");
// trim the ASCII control characters at the end of $binary
// (from 0 to 31 inclusive)
?>

相关文章

基于flush()不能按顺序输出时的解决办法

如果是在linux下, 首先确认是否添加 ob_start() 和 ob_flush().复制代码 代码如下:ob_start();for ($i=1; $i<=10; $i++)...

迅速确定php多维数组的深度的方法

例如有一个多维数组: 复制代码 代码如下: array( array( array(1,3,4), array( array( 1,2,3 ) ) ), array( array(1,2...

php判断目录存在的简单方法

PHP判断文件或目录是否存在 file_exists:判断文件是否存在 $file = "check.txt"; if(file_exists($file)) { echo...

具有时效性的php加密解密函数代码

复制代码 代码如下:<?phpfunction encode_pass($tex,$key,$type="encode",$expiry=0){   ...

php自动适应范围的分页代码

复制代码 代码如下:<?php function page($page,$total,$phpfile,$pagesize=10,$pagelen=7){  &...