php keyword blocker, how to know which word is an illegal phrase after interception

Source: Internet
Author: User
php keyword blocker, how do you know which word is an illegal phrase after interception?
First, panduan.php

/**
* Determine if a keyword exists in the text
*/
function Filter_text ($text, $badstring) {
$filter = Explode (' | ', $badstring);
foreach ($filter as $key) {
if (Strpos ($text, $key)!== false) {
return true;
}
}
return false;
}

?>

Second, filter.php
$badstring = "Stop me | This content | not allowed";
?>

Third, index.php
Require_once ("panduan.php");
Require_once ("filter.php");
$biaoti = "Cannot pass if this content is included!" ";
if (Filter_text ($biaoti, $badstring)) {
echo "Sorry, your hint contains" $***** "text cannot be a table, please delete" This content "text before submitting! ";
Exit ();
}
?>



The above code can correctly intercept the pre-set keyword, but how to write to indicate which keyword is illegal? If you get the content in quotation marks: "$*****"?

Please help the master, thank you!

------Solution--------------------
Change it here into a
if (Strpos ($text, $key)!== false) {
return $key;
}

Over here
if (Filter_text ($biaoti, $badstring)) {
echo "Sorry, your hint contains" $***** "text cannot be a table, please delete" This content "text before submitting! ";
Exit ();
}

Modified into

$badstr =filter_text ($biaoti, $badstring);

if ($BADSTR) {
echo "Sorry, the content you prompted contains". $badstr. " Text cannot be table, please delete "This content" text before submitting! ";
Exit ();
}

About this.
------Solution--------------------
PHP code
 $text = ' Stop me '; $badstring = "/Stop Me | This content | not allowed/"; if (preg_ Match ($badstring, $text, $matchs)) {echo $matchs [0];//var_dump ($MATCHS);} 
------Solution--------------------
about the efficiency of both

Test code:
PHP code
 $start = Microtime (true); $text = ' Stop me '; $badstring = "/Stop Me | This content | not allowed/"; $count = 0;for ($i = 0; $i < 1000000; $i + +): if (Preg_match ($badstring, $text, $matchs)) {$count + = 1;} endfor; $end = Microtime (True);p rintf ("Complete Num:%d Total time:%f sec (Using preg_match ())", $count, $end-$start); 
  • 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.