View Single Post
  #2 (permalink)  
Old 03-12-10, 06:44 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
PHP Code:

<?php

/* Read in from the file here, not in the function - you only need to read the file once */
$wordlist='one|two|three|four';

/* Sample data */
$words=array('stone twoot three fourth','under oven tree','cookie oneder ream');

foreach (
$words as $k => $v)
        echo 
'Words: '.$v.' Cleaned: '.clean($wordlist,$v).PHP_EOL;

function 
clean($wordlist,$value)
{
        return 
preg_replace("/($wordlist)/i"'***',trim($value));
}
?>
Output:

Quote:
Words: stone twoot three fourth Cleaned: st*** ***ot *** ***th
Words: under oven tree Cleaned: under oven tree
Words: cookie oneder ream Cleaned: cookie ***der ream
Reply With Quote