如何删除文本中的最后一个字符? [英] How to delete the last character in the text?
本文介绍了如何删除文本中的最后一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
从字符串中删除最后一个字符
我想删除文本中的最后一个字符..
I want to delete the last character in the text..
例如
我的字符串:示例文本
第二个:example tex
怎么样?
推荐答案
使用 substr一个>
$text = 'Example Text';
$text = substr($text, 0, -1)
substr 接受三个参数,原始文本、start 和长度,它返回原始文本中从 start 开始的给定长度的子字符串.如果 length 为负数,则该字符数将从字符串中排除,这就是为什么使用值 -1 来排除字符串中的最后一个字符的原因.
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.
这篇关于如何删除文本中的最后一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文