如何删除文本中的最后一个字符?
Possible Duplicate:
remove last character from string
I want to delete the last character in the text..
For example
My string: example text
Second : example tex
How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 substr
substr 接受三个参数,原始文本、开始和长度,它返回原始文本中从给定长度开始的子字符串。如果 length 为负数,则将从字符串中排除该数量的字符,这就是为什么使用值 -1 来从字符串中排除最后一个字符。
Use substr
substr takes three arguments, the original text, start and length, it return the substring from the original text starting at start with the given length. If length is negative, that number of characters will be excluded from the string, that's why whe are using the value -1, to exclude the last char from the string.
使用
substr
,它获取原始的子字符串string:0
表示“从头开始”,-1
表示“直到结束前一个字符”。Use
substr
, which gets a substring of the original string:0
means "start at the beginning",-1
means "go until one character before the end".用这个
use this
简单明了,开门见山,
做你的事。
字符串实际上是php中的字符数组。因此,您可以将最后一个索引设置为空字符串。
使用
unset()
会更好,但 php 不允许取消设置字符串索引。Simple and straight to the point
Does your stuff.
Strings are in actuality an array of characters in php. You can therefore set the last index to an empty string.
Using
unset()
would have been nicer but php doesn't allow unsetting string indices.