PHP敏感词替换
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>敏感词替换</title> </head> <body> <form action="" method="post"> <label for="">请输入您的评论:</label><br> <textarea name="pinglun" id="" cols="30" rows="10"></textarea><br> <input type="submit" value="提交"> </form> </body> </html> <?php if ($_POST) { $pinglun=$_POST['pinglun']; $word=['傻逼','二百五','垃圾']; if (str_replace($word, "", $pinglun)!==$pinglun) { echo "<script>alert('您的评论存在敏感词,将会被替换');</script>"; $str=str_replace($word, "***", $pinglun); exit("<script>alert('您替换后的评论是:{$str}');</script>"); }else{ exit("<script>alert('您的评论是:{$pinglun}');</script>"); } } ?>