如何从字符串中修剪子字符串,条件是在其末尾找到


How to trim substring from string with the condition of being found at the end of it?

例如,这将是我修剪条件的标准:

前面有空格的子字符串2将从字符串的末尾删除,但如果在字符串内部和末尾之前找到,则不会删除

The date is 2015将保持不变,但不是字符串the date is 2015 2,从中应该修剪空间和其末尾的2

我知道我可以用explode/implode函数半烤一些东西,但有什么更好的方法可以做到这一点吗?

rtrim($txt, " $foo");

从字符串的右侧修剪选定的字符