Remove the last character from string
Possible Duplicate:
PHP - Remove last character if it's a period?
Which is fastest way to remove last character from string?
I have a string like
a,b,c,d,e,
I would like to remove last ',' and get the remaining string back
OUTPUT: a,b,c,d,e
What the fastest way to do this?
First I try without space rtrim($arraynama,",");
and get error result.
Then I add a space and get good result: $newarraynama=rtrim($arraynama,", ");
你可以使用substr
echo substr('a,b,c,d,e,', 0, -1);
# => 'a,b,c,d,e'
An alternative to substr
is the following, as a function:
substr_replace($string, "", -1)
Is it the fasted? I don't know, but I'm willing to bet these alternatives are all so fast that it just doesn't matter.
链接地址: http://www.djcxy.com/p/9978.html上一篇: XOR变量交换如何工作?
下一篇: 从字符串中删除最后一个字符