我需要删除一个字符串的子串,但只有在该子串位于该字符串结尾时才进行删除。
例如,在以下字符串的结尾处删除“string”:
"this is a test string" -> "this is a test "
"this string is a test string" - > "this string is a test "
"this string is a test" -> "this string is a test"
有什么想法吗?可能需要使用 preg_replace,但是怎么做呢?
s($str)->replaceSuffix('string')
很有帮助,可以在这个独立库中找到。 - caw