Home  >  Article  >  Backend Development  >  php如何去掉字符串最后一个字符

php如何去掉字符串最后一个字符

WBOY
WBOYOriginal
2016-06-23 13:49:381335browse

php如何去掉字符串最后一个字符,$a = 1,2,3,4,      ,注意,是去掉4后面的逗号,而不是去掉4


回复讨论(解决方案)

trim($string, ',');

echo substr($a, 0, -1);

$a='1,2,3,4,';$b=rtrim($a,',');echo $b;

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