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

The function to filter sensitive words does not work.

WBOY
Release: 2016-08-04 09:22:25
Original
1202 people have browsed it

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

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>
Copy after login
Copy after login

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

<code>$mgc[i] >>> $mgc[$i]</code>
Copy after login

This situation may be simpler to write like this

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

<code>function guolv($data){
        $mgc=array("哈哈","哦");
        for ($i=0; $i <count($mgc) ; $i++) { 
          $data=str_replace($mgc[$i], “*”, $data);//原为$msg[i]
        }
          return $data;
      }
      </code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template