Forum Moderators: coopster
$ignore=array("is","a","the");
$sentence="this is the way I want";
//create regular expression, using the items in $ignore,
//which in this case the regular expression will look like: /\b(is|a|the)\b/
$rex = '/\b('.implode('|', $ignore).')\b/';
echo preg_replace($rex, '', $sentence);
$rex = '/\b('.implode('|', $ignore).')\b/i';
$rex = '/\b('.implode('|', $ignore).')\b/iu';
as in Readie's code above
Assuming $ignore will never contain special characters which would trip up the regular expression
$rex = '/\b('.preg_quote(implode('|', $ignore)).')\b/';