Forum Moderators: coopster
$words = array('apple','orange','banana');
$string = 'How was your apple? I like oranges! But bananas are even better!';
$fixed = str_ireplace($words,'(SNIP)',$string);
echo "String: $string<br><br>Fixed: $fixed<br>"; String: How was your apple? I like oranges! But bananas are even better!
Fixed: How was your (SNIP)? I like (SNIP)s! But (SNIP)s are even better! $words = array('apple','orange','banana');
$string = 'How was your apple? I like oranges! But bananas are even better!';
$symb = array('!', '£', '$', '%', '&', '@', '?', '#');
$i = 0;
foreach($words as $word) {
$repl[$i] = '';
$len = strlen($word);
for($o = 0; $o < $len; $o++) {
$count = count($symb);
$ne = $count - 1;
$new = rand(0, $ne);
$repl[$i] .= $symb[$new];
}
$i++;
}
$fixed = str_ireplace($words,$repl,$string);
echo "String: $string<br><br>Fixed: $fixed<br>";
<?php
$words = array(
'/([^ ]{1})?a([^a]{1})?pp([^p]{1})?l([^l]{1})?e([^ ]{1})?/i',
'/([^ ]{1})?o([^o]{1})?r([^r]{1})?a([^a]{1})?n([^n]{1})?g([^g]{1})?e([^ ]{1})?/i',
'/([^ ]{1})?b([^b]{1})?a([^a]{1})?n([^n]{1})?a([^a]{1})?n([^n]{1})?a([^ ]{1})?/i'
);
$symb = array('!', '£', '$', '%', '&', '@', '?', '#');
$string = 'How was your applee? I like ora nges! But banaanas are even better!';
echo '<p>Original: ' . $string . '</p>';
foreach($words as $word){
preg_match_all($word, $string, $out, PREG_PATTERN_ORDER);
$count = count($out[0]);
for($i = 0; $i < $count; $i++) {
$repl[$i] = '';
$len = strlen($out[0][$i]);
for($o = 0; $o < $len; $o++) {
$coun = count($symb);
$ne = $coun - 1;
$new = rand(0, $ne);
$repl[$i] .= $symb[$new];
}
$string = str_ireplace($out[$i], $repl[$i], $string);
}
}
echo '<p>Fixed: ' . $string . '</p>';
?>
from spam and swear words?
$bad_patterns = Array (
'b*cc\s*:', // attempted malformed injection
'to\s*:',
'content\-type',
'\[\s*URL.*\]*', // attempted link dropping
'\[\s*LINK.*\]*',
'\%5B\s*URL.*(\%5D)*',
// Etc. . . more here ....
// "example.com" is YOUR site. A common attack is
// "anything" @example.com to make it look like it
// came from YOU
'example.com'
);
foreach ($bad_patterns as $v) {
if (preg_match("/$v/i",$value)) {
$trap .= "SPAM: $value found in " . $key . " field.\n";
$spam_in = 1;
}
}
function filter_bad_words($list,$input) {
$clean=$is_bad=NULL;
$word_input = preg_split('/\s+/',$input); // or explode
foreach ($word_input as $wd) {
//gets rid of t*h*i*s, t-h-i-s, and similar
$is_bad=0;
$wd = preg_replace('/[^a-z0-9\.,\'"]+/i','',$word);
foreach ($list as $filter) {
if (preg_match("/$filter/i",$wd)) {
$wd = preg_replace('/./','#',$wd);
}
}
$clean .= ($is_bad==1)?$wd:$word;
$clean . " " ;
}
return $clean;
}