There is a simple function for the same see:
lets say you want to remove asdf from a string $title which is
$title = “Appleasdf ” ;
str_replace('asdf','', $title)
Here we have replaced asdf from blank so now your string is
$title = “Apple”;
I hope you would use this according to your need.