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)
?>

相关文章

php中通过数组进行高效随机抽取指定条记录的算法

php使用数组array_rand()函数进行高效随机抽取指定条数的记录,可以随机抽取数据库中的记录,适合进行随机展示和抽奖程序。 该算法主要是利用php的array_rand()函数,...

PHP pear安装配置教程

什么是PEAR? PEAR是PHP扩展与应用库(the PHP Extension and Application Repository)的缩写。它是一个PHP扩展及应用的一个代码仓库,...

检测png图片是否完整的php代码

复制代码 代码如下: <?php $filename = './D243375_0.png'; $filename = realpath($filename); if (!file...

浅谈PHP命令执行php文件需要注意的问题

require_once '/data/web/fewfawef/wwwroot/Public/queenchuli/common/mysql.php'; 里面必须要写绝对路径 写死 才...

PHP实现类似于C语言的文件读取及解析功能

本文实例讲述了PHP实现类似于C语言的文件读取及解析功能。分享给大家供大家参考,具体如下: $log_file_name = 'D:/static/develop/kuai_zhi/...