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>");
		}
	}

 ?>
相關文章
相關標籤/搜索