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 :
I suppose you could use a regular expression, which would match string
and, then, end of string, coupled with the preg_replace() function.
Something like this should work just fine :
$str = "this is a test string";
$new_str = preg_replace('/string$/', '', $str);
Notes :
string
matches... well... string
$
means end of stringFor more informations, you can read the Pattern Syntax section of the PHP manual.