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


311

如何在php的字符串末尾删除3个字符?“ abcabcabc”将变为“ abcabc”!

php  string 

1
s($str)->cutEnd(3)如在该独立库中所发现的,您可能会发现有帮助。这是Unicode或多字节安全的。
caw

Answers:


668

做就是了:

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

strlensubstr docs所述,您无需使用呼叫:

如果给定length且为负数,则将从字符串末尾省略许多字符



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.