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);