Guest User

Untitled

a guest
Oct 1st, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. $sentence = "I dont give a badwordtwo";
  2.  
  3. $values = array("badwordone","badwordtwo","badwordthree","badwordfour");
  4.  
  5. $var = "This is my phrase.";
  6. $var = str_ireplace( array("this", "phrase"), array("****", "*****"), $var);
  7.  
  8. $var = str_ireplace( array("this", "phrase"), "", $var);
  9.  
  10. <?PHP
  11. $banned = array('bad','words','like','these');
  12.  
  13. $looksLikeSpam = false;
  14. foreach($banned as $naughty){
  15. if (strpos($string,$naugty) !== false){
  16. $looksLikeSpam=true;
  17. }
  18. }
  19.  
  20. if ($looksLikeSpam){
  21. echo "You're GROSS! Just... ew!";
  22. die();
  23. }
  24. ?>
  25.  
  26. $sentence = "I dont give a badwordtwo";
  27. $values = array("badwordone","badwordtwo","badwordthree","badwordfour");
  28. $s = explode(" ",$sentence);
  29. foreach ($s as $a=>$b){
  30. if (in_array($b, $values)) {
  31. echo "Got $b";
  32. }
  33. }
  34.  
  35. $ php test.php
  36. Got badwordtwo
  37.  
  38. $sentence = "I dont give a badwordtwo";
  39. $values = array("badwordone","badwordtwo","badwordthree","badwordfour");
  40. $s = explode(" ",$sentence);
  41. var_dump(array_intersect($s, $values));
  42.  
  43. $ php test.php
  44. array(1) {
  45. [4]=>
  46. string(10) "badwordtwo"
  47. }
  48.  
  49. <?php
  50. // Provides: <body text='black'>
  51. $bodytag = str_replace("%body%", "black", "<body text='%body%'>");
  52.  
  53. // Provides: Hll Wrld f PHP
  54. $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
  55. $onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
  56.  
  57. // Provides: You should eat pizza, beer, and ice cream every day
  58. $phrase = "You should eat fruits, vegetables, and fiber every day.";
  59. $healthy = array("fruits", "vegetables", "fiber");
  60. $yummy = array("pizza", "beer", "ice cream");
  61.  
  62. $newphrase = str_replace($healthy, $yummy, $phrase);
  63.  
  64. // Provides: 2
  65. $str = str_replace("ll", "", "good golly miss molly!", $count);
  66. echo $count;
  67. ?>
  68.  
  69. public static function censor($str, $badwords, $replacement = '#', $replace_partial_words = TRUE)
  70. {
  71. foreach ((array) $badwords as $key => $badword)
  72. {
  73. $badwords[$key] = str_replace('*', 'S*?', preg_quote((string) $badword));
  74. }
  75.  
  76. $regex = '('.implode('|', $badwords).')';
  77.  
  78. if ($replace_partial_words === FALSE)
  79. {
  80. $regex = '(?<=b|s|^)'.$regex.'(?=b|s|$)';
  81. }
  82.  
  83. $regex = '!'.$regex.'!ui';
  84.  
  85. if (strlen($replacement) == 1)
  86. {
  87. $regex .= 'e';
  88. return preg_replace($regex, 'str_repeat($replacement, strlen('$1'))', $str);
  89. }
  90.  
  91. return preg_replace($regex, $replacement, $str);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment