可能重复:
如果单词包含特定字符串,则删除整个单词
如何删除包含单词的整个单词?例如,'releas' 应该删除已发布、发布等。
/* 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;