Home > Backend Development > PHP Tutorial > How to filter and highlight illegal characters_PHP Tutorial

How to filter and highlight illegal characters_PHP Tutorial

WBOY
Release: 2016-07-21 16:07:43
Original
905 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 "other 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++;
$CheckedMessage=preg_replace("/(? will not be replaced. If filtering is required Characters dropped in $StartReplace or $EndReplaceHtml need to modify the rules, otherwise there will be garbled characters if($AssumeLength!=1){//If the currently intercepted character is a Chinese character
$j++; 🎜>                                                                                              !

?>




http://www.bkjia.com/PHPjc/314989.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/314989.html

TechArticle

? //I am just doing a test. If you use a string similar to tmd, you must pay attention to 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