Friday, November 9, 2018

Bad words Detection in Input PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post">
<table width="779" border="1" cellspacing="0" cellpadding="10">
  <tr>
    <th scope="row">Enter String :</th>
    <td><textarea name="txtstr" id="txtstr"></textarea></td>
  </tr>
  <tr>
    <th colspan="2" scope="row"><input type="submit" name="btnsubmit" id="btnsubmit" value="Submit" /></th>
  </tr>
</table>
</form>
</body>
</html>
<?php
$wrds=array('oh','allas','wah','omg');
if(isset($_POST['btnsubmit'])){
$str=$_POST['txtstr'];
$a=explode("\n",$str);
foreach($a as $val){
$arr=explode(" ",$val);
foreach($arr as $m){
foreach($wrds as $w){
if(strcmp($w,$m)==0){ echo 'contains bad words.'; exit;
}
}
}
}
}
?>

No comments:

Post a Comment