This article introduced the PHP shielding keyword realization method, a total of two kinds of realization way, concretely as follows:
The first of these methods
The idea is to match the keyword with the positive, and replace the key word with another character.
$STR = "/Your big Uncle | You're paralyzed | Sb| you the mother/"; Keyword Regular string
$string = "What the hell are you doing?" Text string
echo preg_replace ($str, "*", $string); Preg_replace () performs a matching and replacement of a regular expression
OK method The end is very simple to see people in the time can be based on the idea of their own first to think
Method Two
Ideas
1. Put the keyword in a txt document to be separated by a certain conformance, using the file_get_contents () function to read the keyword document
2. Use the function explode () to split the string into a series of cyclic array strpos () to find the matching keyword
Code
Header (' content-type:textml; charset=utf-8; ');
function Strposfuck ($content)
{
$fuck = file_get_contents (' keyWords.txt '); Read the keyword text information
$content = Trim ($content); $FUCKARR = explode ("\ n", $fuck); Converts a 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 cycle
# code ...
}
if (Strpos ($content, Trim ($FUCKARR [$i]))!= false)
{return
$fuckArr [$i]; return keyword
# code ...
} if match to key word return false; Returns False if there is no match to the
keyword
$content = "I met an SB in your uncle today";
$key = Strposfuck ($content);
if ($key)
{
echo exists a keyword. $key;
# code ...
}
else
{
echo ' OK ';
}
Be careful , be sure to go to the air.
The Strops () function returns the value of either false or the position of the keyword when judging the attention
After the success, you can think about how to return all the matching keywords to form a string or an array.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.