Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $sentence = "I dont give a badwordtwo";
- $values = array("badwordone","badwordtwo","badwordthree","badwordfour");
- $var = "This is my phrase.";
- $var = str_ireplace( array("this", "phrase"), array("****", "*****"), $var);
- $var = str_ireplace( array("this", "phrase"), "", $var);
- <?PHP
- $banned = array('bad','words','like','these');
- $looksLikeSpam = false;
- foreach($banned as $naughty){
- if (strpos($string,$naugty) !== false){
- $looksLikeSpam=true;
- }
- }
- if ($looksLikeSpam){
- echo "You're GROSS! Just... ew!";
- die();
- }
- ?>
- $sentence = "I dont give a badwordtwo";
- $values = array("badwordone","badwordtwo","badwordthree","badwordfour");
- $s = explode(" ",$sentence);
- foreach ($s as $a=>$b){
- if (in_array($b, $values)) {
- echo "Got $b";
- }
- }
- $ php test.php
- Got badwordtwo
- $sentence = "I dont give a badwordtwo";
- $values = array("badwordone","badwordtwo","badwordthree","badwordfour");
- $s = explode(" ",$sentence);
- var_dump(array_intersect($s, $values));
- $ php test.php
- array(1) {
- [4]=>
- string(10) "badwordtwo"
- }
- <?php
- // Provides: <body text='black'>
- $bodytag = str_replace("%body%", "black", "<body text='%body%'>");
- // Provides: Hll Wrld f PHP
- $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
- $onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
- // Provides: You should eat pizza, beer, and ice cream every day
- $phrase = "You should eat fruits, vegetables, and fiber every day.";
- $healthy = array("fruits", "vegetables", "fiber");
- $yummy = array("pizza", "beer", "ice cream");
- $newphrase = str_replace($healthy, $yummy, $phrase);
- // Provides: 2
- $str = str_replace("ll", "", "good golly miss molly!", $count);
- echo $count;
- ?>
- public static function censor($str, $badwords, $replacement = '#', $replace_partial_words = TRUE)
- {
- foreach ((array) $badwords as $key => $badword)
- {
- $badwords[$key] = str_replace('*', 'S*?', preg_quote((string) $badword));
- }
- $regex = '('.implode('|', $badwords).')';
- if ($replace_partial_words === FALSE)
- {
- $regex = '(?<=b|s|^)'.$regex.'(?=b|s|$)';
- }
- $regex = '!'.$regex.'!ui';
- if (strlen($replacement) == 1)
- {
- $regex .= 'e';
- return preg_replace($regex, 'str_repeat($replacement, strlen('$1'))', $str);
- }
- return preg_replace($regex, $replacement, $str);
- }
Advertisement
Add Comment
Please, Sign In to add comment