Is there a way to remove everything before and including the last instance of a certain character?
I have multiple strings which contain >
, e.g.
You could use a regular expression...
$str = preg_replace('/^.*>\s*/', '', $str);
CodePad.
...or use explode()
...
$tokens = explode('>', $str);
$str = trim(end($tokens));
CodePad.
...or substr()
...
$str = trim(substr($str, strrpos($str, '>') + 1));
CodePad.
There are probably many other ways to do it. Keep in mind my examples trim the resulting string. You can always edit my example code if that is not a requirement.