Home  >  Article  >  Backend Development  >  php 除了字符串

php 除了字符串

WBOY
WBOYOriginal
2016-06-13 10:56:24931browse

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, ",")

Statement:
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