Using regexp may fails if the substring has special characters.
The following will work with any strings:
$substring = 'string';
$str = "this string is a test string";
if (substr($str,-strlen($substring))===$substring) $str = substr($str, 0, strlen($str)-strlen($substring));