Home >Backend Development >PHP Tutorial >The function to filter sensitive words does not work.
<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>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>