如何在php中的字符串末尾删除3个字符?

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

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


想:

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

你需要使用strlen呼叫说,因为,在substr文档:

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



1
<?php echo substr($string, 0, strlen($string) - 3); ?>