php 除了字符串

WBOY
Release: 2016-06-13 10:56:24
Original
929 people have browsed it

php 去掉字符串

今天项目中用到,去掉字符串中的最后一个字符

原字符串1,2,3,4,5,6,

去掉最后一个字符",",最终结果为1,2,3,4,5,6

代码如下:

$str = "1,2,3,4,5,6,";

$newstr = substr($str,0,strlen($str)-1);

echo $newstr;

系统自带的函数也可实现这样的效果,两种方法:

1) substr($str, 0, -1)

2)rtrim($str, ",")

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!