ok so let me see...
function remove_words($str) {
$remove = array('SOMNAMBULIST', 'EREGO', 'HERETOFORE');
$patterns = array();
foreach($remove as $rm) {
$quoted = preg_quote($rm, '/');
$patterns[] = '/(\b' . $quoted . '\b\s?|\s?\b' . $quoted . '\b\s?(?=$|\n))/i';
}
return preg_replace($patterns, '', $str);
} // remove_words()
echo "'" . remove_words('I think erego I am') . "'\n"; // needs a space!
echo "'" . remove_words('Heretofore unknown') . "'\n"; // works great
echo "'" . remove_words('I think heretofore erego i am') . "'\n"; // works great
echo "'" . remove_words('I was satisfied heretofore') . "'\n"; // works great
I believe I've covered all the boundary conditions in the examples and it seems to work:
'I think I am'
'unknown'
'I think i am'
'I was satisfied'
I think you nailed it drakla. The expression itself is a bit scary to me (this is to be expected from the undead i suppose) so I think I'll stick with my previous function which I can grasp a little better.
The scariest parts are all those question marks. I'm not really sure what they do.
Thanks for the valiant effort guys!