Home >Backend Development >PHP Tutorial >php array search key function

php array search key function

高洛峰
高洛峰Original
2016-11-29 13:36:061245browse

Provide three methods to determine whether a string includes the words we defined, which is more suitable for keyword filtering in messages, comments and other addresses. The example code is as follows:

$crud = array('China||| Our country|||地', 'kelon|||lerke|||sb', 'sesscxx');

$crud = join('|',$crud);

$crud = str_replace('||| ', '|', $crud);

$pat = "/({$crud})/i";

$txt = 'I know who you are sdfex in China! ! ';

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)

                                                                                                                                                                                                                                                                                                                                    using val)

                                                                                                                                                                         $check++;                                                                                                                                          

                                                                     ​​​{                                                                                                      }

            return false;                                                                       $test1 = 'I am Chinese. There are many people in my country. The earth is full of people.-__-!! What a good sentence.';

var_dump(checkcrud($test1, $crud));

Method Third, the code is as follows:

function lktest($v,$keyword){

foreach ($v as $k){

if (strpos($k,"|||")!==false){

$kelon=explode("|||",$k);

//Find the maximum value of the array

$b=count($kelon);

foreach($kelon as $t){

as $t //echo "sensitive keyword";

                                                                                                     When equal to $a, all ||| keywords appear

if ($a==$b){

echo "sensitive keyword";

}

}

elseif(preg_match(' /'.$k.'/i',$keyword)){

echo "sensitive keyword";//open source code phpfensi.com

}

}

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn