<?php
function Filter_word( $str, $fileName )
{
if ( !($words =
file_get_contents( $fileName )) ){
die('file read error!');
}
$str = strtolower($str);
//var_dump($words);
$word = preg_replace("/[1,2,3] | /i", '', $words);
//$wor = substr($word,0,-1);
//$w = preg_replace("|/|i", '/', $word);
//echo "<pre>";
//var_dump($w);
//$words = "aaa|bbb|ccc|ddd|eee";
$matched = preg_replace('/'.$word.'/i', '***', $string);
return $matched;
}
$content = "<a href='#'>我要aaafsdfbbb</a>";
if ($result = Filter_word($content, './words.txt') ){
echo $result;
echo "替换成功 ";
}else{
echo "替换失败! ";
?>