The example of this article summarizes the PHP array lookup function. Share to everyone for your reference. Specifically as follows:
Here are three ways to determine whether a string contains our defined words, which is more suitable for keyword filtering in the address of a message, comment, and so on, with the example code as follows:
Copy Code code as follows:
$crud = Array (' China | | | | China | | | Earth ', ' kelon| | | lerke| | | SB ', ' sesscxx ');
$crud = Join (' | ', $crud);
$crud = Str_replace (' | | | | ', ' | ', $crud);
$pat = "/({$crud})/I";
$txt = ' I know China you are sdfex who!! ';
preg_match/*_all*/($pat, $txt, $matches);
Var_dump ($matches);
Method Two, the code is as follows:
Copy Code code as follows:
function Checkcrud ($STR, $crud)
{
if (Is_array ($crud) &&!emptyempty ($crud))
{
foreach ($crud as $value)
{
if (Strpos ($value, ' | | | | ')!== false)
{
$cruds = Explode (' | | | | ', $value);
$num = count ($cruds);
$check = 0;
foreach ($cruds as $val)
{
if (Strpos ($str, $val)!== false)
{
$check + +;
}
}
if ($check = = $num)
{
return true;
}
}
Else
{
if (Strpos ($str, $value)!== false)
{
return true;
}
}
}
return false;
}
}
$crud = Array (' China | | | | China | | | Earth ', ' kelon| | | lerke| | | Ssxb ', ' aaa ');
$test 1 = ' I am Chinese. There are many people in our country. The earth is full of people.-__-!! Good xx's sentence.
Var_dump (Checkcrud ($test 1, $crud));
Method Three, the code is as follows:
Copy Code code as follows:
function Lktest ($v, $keyword) {
foreach ($v as $k) {
if (Strpos ($k, "| | |")! ==false) {
$kelon =explode ("| | |", $K);
To find the maximum value of an array
$b =count ($kelon);
foreach ($kelon as $t) {
echo $t. ' <br> ';
if (Preg_match ('/'. $t. '/I ', $keyword)) {
echo "Sensitive key word";
$a = $a +1;
}
else{
$a = ';
}
}
If the maximum array value is equal to $a, then all | | | The keys are all there.
if ($a = = $b) {
echo "Sensitive key word";
}
}
ElseIf (Preg_match ('/'. $k. '/I ', $keyword)) {
echo "Sensitive key word";
}
}
}
I hope this article will help you with your PHP program design.