Home > Backend Development > PHP Tutorial > To whygod, how to filter and highlight illegal characters! _PHP Tutorial

To whygod, how to filter and highlight illegal characters! _PHP Tutorial

WBOY
Release: 2016-07-13 11:00:22
Original
852 people have browsed it

//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 if(strstr($CheckedMessage,$CheckedWords[$i])){ //You can remove
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

www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/631813.htmlTechArticle? //I'm just doing a test. If you use a string like tmd again, you must pay attention. If the character The characters in the string appear in $StartReplaceHtml or $EndReplaceHtml, you need to modify it...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template