To Whygod, how to filter highlighting illegal characters!

Source: Internet
Author: User
?
I'm just doing a test, and if you use a TMD-like string, be sure to 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's X's. He.... X... ....     How to Are you M d "; The message to is checked
echo $CheckedMessage. " <br> ";
$CheckedWords =array ("He X's", "TMD")//to filter the illegal characters, if you need to put a single character also filtered, such as: he ererX000 to filter out his, x, you do not need to set the filter character "he X" as long as the set to $ Checkedwords=array ("He", "X", "the");
$StartReplaceHtml = "<u><b><font color= ' #FF0000 ' >";
$EndReplaceHtml = "</font></b></u>";
$CheckOther = true;//Sets the indicator bit, whether a single character is displayed, and if set to true, the following if (Strstr ...) You don't need it.
for ($i =0; $i <count ($CheckedWords); $i + +) {
if (Strstr ($CheckedMessage, $CheckedWords [$i]) {//Here you can remove
$CheckedMessage =eregi_replace ($CheckedWords [$i], $StartReplaceHtml. $CheckedWords [$i]. $EndReplaceHtml, $ Checkedmessage)//If you only filter strings such as "he X" (is a string, not a single character), you can write the sentence directly and set the $checkother to False
}
if ($CheckOther = = True) {
$CharStringLength = strlen ($CheckedWords [$i]);
for ($j =0; $j < $CharStringLength; $j + +) {
$AssumeLength =1;//assumed intercept length
if (Ord ($CheckedWords [$i], $j, $AssumeLength)) (>0xa0) {//If the Chinese character, assuming the length plus a
$AssumeLength + +;
}
$SubstrChar = substr ($CheckedWords [$i], $j, $AssumeLength);

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.