开发者

Trimming the end of a string if it contains a certain character?

Let's say I have a string like this: asd开发者_JAVA技巧f, asdf, asdf,. There is a comma and a space at the end. I want to trim that off only if it is a comma and a space. If the string looks like this asdf, asdf, asdf then I do not want it to trim off the last two characters. How can I do this?


rtrim($str, ", ");

That will trim all of the spaces and commas from the right of the string. It is faster than a regexp.


$str = preg_replace('~, $~', '', $str);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜