Remove a part of a string, but only when it is at the end of the string

前端 未结 7 2338
广开言路
广开言路 2020-12-14 05:04

I need to remove a substring of a string, but only when it is at the END of the string.

for example, removing \'string\' at the end of the following strings :

7条回答
  •  青春惊慌失措
    2020-12-14 05:53

    You can use rtrim().

    php > echo rtrim('this is a test string', 'string');
    this is a test 
    

    This will work only in some cases, as 'string' is just a characters mask and char order will not be respected.

提交回复
热议问题