<?
//ÎÒÖ»ÊÇ×oÒ»¸o²aÊÔ£¬Èç¹uÔÙÓÃÀaËÆtmdµÄ×Öu´®£¬Ò»¶¨Òª×¢Òa£¬Èç¹u×Öu´®ÖеÄ×Öu³oÏÖÔÚ$StartReplaceHtml»oÕß$EndReplaceHtmlÖУ¬ÄaÐeÒªÐÞ¸ÄÏÂÃaeµÄpreg_replaceÖеĹaeÔo
$CheckedMessage="Hello!!ËuXµÄ..Ëu....X...µÄ....How are you m d "; //the message to be checked
echo $CheckedMessage."
";
$CheckedWords=array("ËuXµÄ","tmd");//Òª¹ýÂ˵ÄǨ×Öu£¬Èç¹uÄaÐeÒª°Ñµ¥¸oµÄ×ÖuÒ²¹ýÂË£¬±ÈÈ磺ËuererX000µÄ¹ýÂ˳oÀ´Ëu£¬X£¬µÄ£¬Äa¾Íû±ØÒª°Ñ¹ýÂË×ÖuÉeÖóÉ"ËuXµÄ"Ö»ÒªÉeÖóÉ$CheckedWords=array("Ëu"£¬"X","µÄ");¾Í¿ÉÒÔÁË
$StartReplaceHtml="";
$EndReplaceHtml="";
$CheckOther= true;//ÉeÖñeʾ룬ÊÇñÏÔʾµ¥¸oµÄ×Öu£¬Èç¹uÉeÖóÉtrue£¬ÏÂÃaeµÄif(strstr¡¡)¾Í²»ÐeÒªÁË
for($i=0;$i<count($CheckedWords);$i++){
if(strstr($CheckedMessage,$CheckedWords[$i])){ //´Ë´¦¿ÉÈ¥µo
$CheckedMessage=eregi_replace($CheckedWords[$i],$StartReplaceHtml.$CheckedWords[$i].$EndReplaceHtml,$CheckedMessage);//Èç¹uÖ»¹ýÂËÖiÈç"ËuXµÄ"×Öu´®£¨ÊÇ×Öu´®£¬²»Êǵ¥¸o×Öu£(C)£¬¿ÉÒÔÖ±½ÓдÕa¾a£¬Í¬Ê±°Ñ$CheckOtherÉeÖóÉfalse
}
if($CheckOther == true){
$CharStringLength = strlen($CheckedWords[$i]);
for($j=0;$j<$CharStringLength;$j++){
$AssumeLength=1;//¼Ù¶¨½ØÈ¡³¤¶È
if(ord(substr($CheckedWords[$i],$j,$AssumeLength))>0xa0){//Èç¹uºº×Ö£¬¼Ù¶¨³¤¶È¼ÓÒ»
$AssumeLength++;
}
$SubstrChar = substr($CheckedWords[$i],$j,$AssumeLength);
$CheckedMessage=preg_replace("/(?<!fon)".$SubstrChar."/",$StartReplaceHtml.$SubstrChar.$EndReplaceHtml,$CheckedMessage);//Ìae»»×Öu£¬Í¬Ê±Èç¹u×Öuº¬ÓÐtµÄʱºoÖеÄt²»»a±»Ìae»»£¬Èç¹uÐeÒª¹ýÂ˵oÔÚ$StartReplace»oÕßÔÚ$EndReplaceHtmlÖеĵÄ×Öu£¬ÐeÒªÐ޸ĹaeÔo£¬ñÔoµÄ»°½«»a³oÏÖÂÒÂe
if($AssumeLength!=1){//Èç¹uµ±Ç°½ØÈ¡×ÖuΪºº×Ö
$j++;
}
}
}
}
echo $CheckedMessage;
//Ö»ÊÇÒ»¸o¼oµ¥µÄ²aÊÔ£¬Ï£Íu¶ÔÄaÓÐËu°iÖu£¬Ï£ÍuÄaÄܾÙÒ»*´Èý£¬ºÃÔË£¡
?>