如何删除字符串末尾的逗号? [英] how do i remove a comma off the end of a string?
本文介绍了如何删除字符串末尾的逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除字符串末尾的逗号.现在我正在使用
I want to remove the comma off the end of a string. As it is now i am using
$string = substr($string,0,-1);
但是只会删除字符串的最后一个字符.我正在动态添加字符串,因此有时字符串末尾没有逗号.如果字符串末尾有逗号,我如何让PHP从字符串末尾删除逗号?
but that only removes the last character of the string. I am adding the string dynamically, so sometimes there is no comma at the end of the string. How can I have PHP remove the comma off the end of the string if there is one at the end of it?
推荐答案
$string = rtrim($string, ',');
Docs for rtrim
here
这篇关于如何删除字符串末尾的逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文