How can I remove 3 characters at the end of a string in php?

How can I remove 3 characters at the end of a string in php? "abcabcabc" would become "abcabc"!


Just do:

echo substr($string, 0, -3);

You don't need to use a strlen call, since, as noted in the substr docs:

If length is given and is negative, then that many characters will be omitted from the end of string


<?php echo substr("abcabcabc", 0, -3); ?>


<?php echo substr($string, 0, strlen($string) - 3); ?>
链接地址: http://www.djcxy.com/p/26600.html

上一篇: 函数()必须是字符串的一个实例,在PHP 7之前给出的字符串?

下一篇: 我如何删除在PHP字符串的末尾3个字符?