PHP Replacing swear words with phrases

前端 未结 4 1138
旧时难觅i
旧时难觅i 2021-01-17 02:18

So I get how to replace certain words with other ones. What I\'m trying to figure out is how to take a word and replace it with a phrase and eliminate all other input.

4条回答
  •  遇见更好的自我
    2021-01-17 03:10

    Well, in this case you can just check whether there is a "bad word" in the user input string, and if it returns true, echo "You are a potty mouth."

    You would want to use strpos()

    e.g.

    if( strpos($_POST['user_input'],'dog')!==FALSE ) {
        echo('You are a potty mouth');
    }
    

    If you have an array of "bad words" you'll want to loop through them to check any occur within user input.

提交回复
热议问题