Advertisement
Guest User

Untitled

a guest
Sep 10th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2. /*********************************
  3. FILENAME : filter.php
  4. CREATE BY : cahya dsn
  5. PURPOSE : filtering table
  6. CREATE DATE : 2013-01-27
  7. *********************************/
  8. /*
  9. #table creation
  10. use test;
  11. DROP TABLE IF EXISTS `tbfilter`;
  12. CREATE TABLE IF NOT EXISTS `tbfilter` (
  13. `kata` varchar(30) NOT NULL,
  14. UNIQUE KEY `kata` (`kata`)
  15. ) ENGINE=MyISAM;
  16. INSERT INTO `tbfilter`(`kata`) VALUES
  17. ('ada'),('adalah'),('mereka');
  18.  
  19. DROP TABLE IF EXISTS `tbtampung`;
  20. CREATE TABLE IF NOT EXISTS `tbtampung` (
  21. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  22. `kalimat` varchar(255) NOT NULL,
  23. PRIMARY KEY (`id`)
  24. ) ENGINE=MyISAM;
  25.  
  26. */
  27. //database configuration
  28. $dbhost='localhost';
  29. $dbuser='root';
  30. $dbpass='';
  31. $dbname='test';
  32. //database connection
  33. $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
  34. //query to get filtering words data from database
  35. $sql="SELECT * FROM tbfilter";
  36. $result=$db->query($sql);
  37. //variables initialization
  38. $filter=array();
  39. //generate filtering words datas from tbfilter table
  40. // 1. Fetch data from database
  41. while($records=$result->fetch_array()){
  42. $filter[]="/{$records[0]}|/";
  43. }
  44. $result->close();
  45. // 2. get input text to be filtering (e.g from input form)
  46. $input="mereka adalah orang pintar";
  47. // 3. preparing input string
  48. $input=preg_replace("/s/","|",$input);
  49. // 4. filtering input text to get clean output
  50. $output=trim(preg_replace('!s+!', ' ',str_replace("|"," ",preg_replace($filter, '', $input))));
  51. // 5. build query to store output text to tbtampung table
  52. $sql="INSERT INTO tbtampung(`id`,`kalimat`)VALUES(NULL,'$output')";
  53. // 6.execute the query
  54. $db->query($sql);
  55. $db->close();
  56. echo $output;
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement