How to filter and highlight illegal characters for whygod!
Source: Internet
Author: User
? I'm just doing a test. if you use a string similar to tmd, be sure to note that if the character in the string appears in $ StartReplaceHtml or $ EndReplaceHtml, you need to modify the following preg_replace rule $ CheckedMessageHello !! He X... he... X... of... Howareyoumd; themessagetobechecke // I'm just doing a test. if you use a string similar to tmd, you must note that if the character in the string appears in $ StartReplaceHtml or $ EndReplaceHtml, you need to modify the rules in the following preg_replace.
$ CheckedMessage = "Hello !! He X... he... X... of... How are you m d "; // the message to be checked
Echo $ CheckedMessage ."
";
$ CheckedWords = array ("its X", "tmd"); // The Invalid character to be filtered. if you need to filter a single character, for example: ererX000 filters out his, X, and so on, you don't have to set the filter character to "his X" as long as it is set to $ CheckedWords = array ("He ", "X", "");
$ StartReplaceHtml ="
"; $ EndReplaceHtml ="";
$ CheckOther = true; // sets the flag to whether a single character is displayed. if it is set to true, the following if (strstr ......) No
For ($ I = 0; $ I If (strstr ($ CheckedMessage, $ CheckedWords [$ I]) {// this can be removed
$ CheckedMessage = eregi_replace ($ CheckedWords [$ I], $ StartReplaceHtml. $ CheckedWords [$ I]. $ EndReplaceHtml, $ CheckedMessage); // If you only filter strings such as "X" (string, not a single character), you can directly write this sentence, set $ CheckOther to false.
}
If ($ CheckOther = true ){
$ CharStringLength = strlen ($ CheckedWords [$ I]);
For ($ j = 0; $ j <$ CharStringLength; $ j ++ ){
$ AssumeLength = 1; // assume the truncation length.
If (ord (substr ($ CheckedWords [$ I], $ j, $ AssumeLength)> 0xa0) {// if the Chinese character is entered, add one to the length
$ AssumeLength ++;
}
$ SubstrChar = substr ($ CheckedWords [$ I], $ j, $ AssumeLength );
$ CheckedMessage = preg_replace ("/(? If ($ AssumeLength! = 1) {// if the current truncated character is a Chinese character
$ J ++;
}
}
}
}
Echo $ CheckedMessage;
// It's just a simple test. I hope it will be helpful to you, and I hope you can put it together. good luck!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service