<?php/* Read in from the file here, not in the function - you only need to read the file once */$wordlist[] = 'one';$wordlist[] = 'two';$wordlist[] = 'three';$wordlist[] = 'four';/* Sample data */$words = 'stone twoot three fourth under oven tree cookie oneder ream one sixone threetwo fournine four';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;?>
Words: stone twoot *** fourth under oven tree cookie oneder ream *** sixone threetwo fournine ***