Home > Article > Backend Development > To whygod, how to filter and highlight illegal characters! _PHP Tutorial
//I am just doing a test. If you use a string similar to tmd again, you must pay attention. If the characters in the string appear in $StartReplaceHtml or $EndReplaceHtml, you need to modify the following preg_replace. Rules
$CheckedMessage="Hello!! He X's...He...X...'s...How are you m d "; //the message to be checked
echo $CheckedMessage. "
";
$CheckedWords=array("his If he, X, comes out, you don’t need to set the filter character to "his ="";
$EndReplaceHtml="";
$CheckOther= true;//Set the flag bit to determine whether to display a single character. If set to true, the following if(strstr...) is not needed
for($i=0;$i
here $CheckedMessage=eregi_replace($CheckedWords[$i],$StartReplaceHtml. $CheckedWords[$i].$EndReplaceHtml,$CheckedMessage);//If you only filter strings such as "his X" (it is a string, not a single character), you can write this sentence directly and set $CheckOther to false
}
if($CheckOther == true){
$CharStringLength = strlen($CheckedWords[$i]);
for($j=0;$j<$CharStringLength;$j++ ; Add one
$AssumeLength++;
}
$SubstrChar = substr($CheckedWords[$i],$j,$AssumeLength);
http://www.bkjia.com/PHPjc/631813.html