Possible Duplicate:
Remove entire word if the word contains specific string
How I can remove an entire word that contains a word?
For example, ‘releas’ should delete released, releases releasing etc.
/* Read in from the file here, not in the function - you only need to read the file once */
$wordlist = array('release','announce');
/* Sample data */
$words = 'adobe releases releases Acrobat X';
foreach ($wordlist as $v)
$words = clean($v,$words);
function clean($wordlist,$value)
{
return preg_replace("/\b$wordlist\b/i", '***',trim($value));
}
echo 'Words: '.$words.PHP_EOL;
You can loop through your
$wordlistand doing it in one replace
Update:
Looking through other answers and comments, it seems I haven’t looked properly at the question. If
$wordlistis not an array, you can just use @fthiella’s answer.