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对象克隆clone用法示例

本文实例讲述了PHP对象克隆clone用法。分享给大家供大家参考,具体如下: 浅克隆:只是克隆对象中的非对象非资源数据,即对象中属性存储的是对象类型,则会出现克隆不完全 <&#...

php获取通过http协议post提交过来xml数据及解析xml

php 如何获取请求的xml数据,对方通过http协议post提交过来xml数据,php如何获取到这些数据呢?复制代码 代码如下: <?php $xml_data ='<AA...

PHP JS Ip地址及域名格式检测代码

PHP IP地址格式检测函数 复制代码 代码如下:function checkIp($ip){    $ip = str_replace(" ", "",...

Windows2003下php5.4安装配置教程(Apache2.4)

Windows2003下php5.4安装配置教程(Apache2.4)

直接配置php一直使用如同《【php】本地开发环境的部署与helloworld》的一键傻瓜包,被批为极度不专业,关键是这些一键傻瓜包LAMP的版本不好控制,端口什么的也不好调。曾经在Li...

PHP 日志缩略名的创建函数代码

复制代码 代码如下:function create_slug($string){ $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string)...