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

后端 未结 3 1040
自闭症患者
自闭症患者 2021-01-29 21:02

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

3条回答
  •  误落风尘
    2021-01-29 21:44

    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

提交回复
热议问题