note 73678 deleted from function.eregi by nlopess
| From: | nlopess@php.net | Date: | Tue, 06 Mar 2007 17:23:26 +0000 |
| Subject: | note 73678 deleted from function.eregi by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124166@lists.php.net to get a copy of this message | ||
Note Submitter: tal_ashkenazi
----
here is a php & database bad words filter, takes words from table called bad_words_lang, and
returns it in to the function.
the function gives array with replaced words, total words count, how much bad words found in number,
and how much bad words found in percents:
(
[orginal_text] => fuck off man i dont want to do it
[replaced_text] => *** off man i dont want to do it
[total_words] => 9
[found_count] => 1
[found_percent] => 11
[found_percent_syntax] => %11
)
<?php
function language_filter($string,$lang) {
// USAGE:
// make a table called bad_words_lang (words, id, lang_id). and put inside a bad words
// use :$a=language_filter($char,1); print_R($a);
$string_orginal=$string;
$count_total=count(explode(" ",$string));
$obscenities_db_q=mysql_query("select * from bad_words_lang where
lang_id='$lang'");
if (!$obscenities_db_q) {
die('Invalid query: ' . mysql_error()); exit;
}
while($obscenities_db_r=mysql_fetch_array($obscenities_db_q)) {
$obscenities[] =$obscenities_db_r[word];
}
s($obscenities);
foreach ($obscenities as $curse_word) {
if (stristr(trim($string),$curse_word)) {
$string = eregi_replace($curse_word,"±¶´",trim($string));
$cur_found = substr_count ($string, '±¶´');
$Replaced = eregi_replace($curse_word,$stars,trim($string));
$Replaced=str_replace("±¶´","***",$Replaced);
}
}
$make_percents=floor($cur_found/$count_total*100);
return array(
"orginal_text"=>"$string_orginal",
"replaced_text"=>"$Replaced",
"total_words"=>"$count_total",
"found_count"=>"$cur_found",
"found_percent"=>"$make_percents",
"found_percent_syntax"=>"%$make_percents"
);
}
$a=language_filter($_POST[your_text],1);
print_R($a);
?>