Now the network information supervision is very strict, especially the blocking keyword. Especially now WEB2.0 era, the content of the website is almost all from the Netizen publishes, the stationmaster manages can. If you want someone to prohibit publishing a keyword on your site, you need to do it beforehand. Use PHP to do keyword masking function style has a variety of, such as regular is the most common one, here is not one by one examples, this article introduces two methods to implement the shielding keywords
The first of these methods
The idea uses the regular to match the keyword, replaces the keyword with another character
$STR = "/Your Uncle | You're paralyzed | What the hell | Sb| your mother/"; Keyword Regular string $string = "What the hell are you doing, SB"; Text string echo preg_replace ($str, "*", $string); Preg_replace () performs a match and replace of a regular expression
OK method At the end is very simple to look at the time you can according to the thinking of their own first to think
Method Two
Ideas
1. Put the keyword into a txt document to be separated by a certain compliance, using the file_get_contents () function to read the keyword document into
2. Use the function explode () to split the string into an array of cyclic arrays Strpos () Find matching keywords
Code
Header (' content-type:textml; charset=utf-8; '); function Strposfuck ($content) { $fuck = file_get_contents (' keyWords.txt '); Read keyword text information $content = Trim ($content); $FUCKARR = explode ("\ n", $fuck); Convert the keyword to an array for ($i =0; $i < count ($FUCKARR), $i + +) { //$FUCKARR [$i] = Trim ($FUCKARR [$i]); if ($fuckArr [$i] = = "") { continue; If the keyword is empty, skip this loop # code ... } if (Strpos ($content, Trim ($FUCKARR [$i]))! = False) { return $fuckArr [$i]; If the keyword is matched, return the keyword # code ... } } return false; Returns False if no match is reached to the keyword $content = "I have a SB for you today"; $key = Strposfuck ($content); if ($key) { echo "presence keyword". $key; # code ... } else { echo "OK"; }
pay attention to the point must go empty must go to empty,
Strops () The return value of the function is either false or the position of the keyword is judged
After success, you can think about how to return all matching keywords to a string or array.