<?
// 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. "<br> ";
$ 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 = "<u> <B> <font color = '# FF0000'> ";
$ EndReplaceHtml = "</font> </B> </u> ";
$ 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 <count ($ CheckedWords); $ 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 );