fork(2) download
  1. <?php
  2.  
  3. $badwords = array('shit', 'fuck'); // Here we can use all bad words from database
  4.  
  5. $text = 'Man, I shot this f*ck, sh/t! fucking fu*ker sh!t f*cking sh\t ;)';
  6.  
  7. echo "filtered words <br>";
  8.  
  9. echo $text."<br/>";
  10.  
  11. $words = explode(' ', $text);
  12.  
  13.  
  14.  
  15. foreach ($words as $word)
  16.  
  17. {
  18.  
  19. $bad= false;
  20.  
  21. foreach ($badwords as $badword)
  22.  
  23. {
  24.  
  25. if (strlen($word) >= strlen($badword))
  26.  
  27. {
  28.  
  29. $wordOk = false;
  30.  
  31. for ($i = 0; $i < strlen($badword); $i++)
  32.  
  33. {
  34.  
  35. if ($badword[$i] !== $word[$i] && ctype_alpha($word[$i]))
  36.  
  37. {
  38.  
  39. $wordOk = true;
  40.  
  41. break;
  42.  
  43. }
  44.  
  45. }
  46.  
  47. if (!$wordOk)
  48.  
  49. {
  50.  
  51. $bad= true;
  52.  
  53. break;
  54.  
  55. }
  56.  
  57. }
  58.  
  59. }
  60.  
  61. echo $bad ? 'beep ' : ($word . ' '); // Here $bad words can be returned and replace with *.
  62.  
  63. }
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
filtered words <br>Man, I shot this f*ck, sh/t! fucking fu*ker sh!t f*cking  sh\t ;)<br/>Man, I shot this beep beep beep beep beep beep  beep ;)