Php array lookup key functions provide three methods to determine whether a string contains the words we have defined. this is more suitable for keyword filtering in the message, comment, and other addresses. the instance code is as follows:
$ Crud = array ('China | China | ', 'kelon | lerke | sb', 'sesscxx ');
$ Crud = join ('|', $ crud );
$ Crud = str_replace ('|', '|', $ crud );
$ Pat = "/({$ crud})/I ";
$ Txt = 'I know China, who are you sdfex !! ';
Preg_match/* _ all */($ pat, $ txt, $ matches );
Var_dump ($ matches );
Method 2: The code is 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 | ', 'kelon | lerke | ssxb', 'AAA ');
$ Test1 = 'I am a chinese. There are many Chinese people. There are all people on the earth .-__-!! Xx sentence .';
Var_dump (checkcrud ($ test1, $ crud ));
Method 3: The code is as follows:
Function lktest ($ v, $ keyword ){
Foreach ($ v as $ k ){
If (strpos ($ k, "| ")! = False ){
$ Kelon = explode ("|", $ k );
// Calculate the maximum value of the array
$ B = count ($ kelon );
Foreach ($ kelon as $ t ){
// Echo $ t .'
';
If (preg_match ('/'. $ t. '/I', $ keyword )){
// Echo "sensitive keywords ";
$ A = $ a + 1;
}
Else {
$ A = '';
}
}
// If the maximum value of the array is equal to $ A, all | keywords are displayed.
If ($ a = $ B ){
Echo "sensitive keywords ";
}
}
Elseif (preg_match ('/'. $ k. '/I', $ keyword )){
Echo "sensitive keywords"; // open-source phpfensi.com
}
}
}