Home >Backend Development >PHP Tutorial >The function to filter sensitive words does not work.

The function to filter sensitive words does not work.

WBOY
WBOYOriginal
2016-08-04 09:22:251192browse

<code>function guolv($data){
        $mgc=array("哈哈","哦");
        for ($i=0; $i <count($mgc) ; $i++) { 
          $data=str_replace($mgc[i], “*”, $data);
        }
          return $data;
      }</code>

I wrote a function to filter sensitive words, but it doesn’t work. Please give me some advice.

Reply content:

<code>function guolv($data){
        $mgc=array("哈哈","哦");
        for ($i=0; $i <count($mgc) ; $i++) { 
          $data=str_replace($mgc[i], “*”, $data);
        }
          return $data;
      }</code>

I wrote a function to filter sensitive words, but it doesn’t work. Please give me some advice.

<code>$mgc[i] >>> $mgc[$i]</code>

This situation may be simpler to write like this

<code class="php">$mgc=array("哈哈","哦");
str_replace($mgc, '*', $mgc);</code>

<code>function guolv($data){
        $mgc=array("哈哈","哦");
        for ($i=0; $i <count($mgc) ; $i++) { 
          $data=str_replace($mgc[$i], “*”, $data);//原为$msg[i]
        }
          return $data;
      }
      </code>
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