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

我如何删除在PHP字符串的末尾3个字符? “abcabcabc”会变成“abcabc”!


做就是了:

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

您不需要使用strlen调用,因为如substr文档中所述:

如果给出长度并且是负数,那么很多字符将在字符串末尾被省略


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


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

上一篇: How can I remove 3 characters at the end of a string in php?

下一篇: How to know that a string starts/ends with a specific string in jQuery?