note 73678 added to function.eregi
| From: | tal_ashkenazi at osu1 dot php dot net | Date: | Tue, 06 Mar 2007 13:33:41 +0000 |
| Subject: | note 73678 added to function.eregi | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124152@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 192.117.122.43
Probable Submitter: 192.117.134.177
----
Manual Page -- http://www.php.net/manual/en/function.eregi.php
Edit -- https://master.php.net/note/edit/73678
Del: integrated -- https://master.php.net/note/delete/73678/integrated
Del: useless -- https://master.php.net/note/delete/73678/useless
Del: bad code -- https://master.php.net/note/delete/73678/bad+code
Del: spam -- https://master.php.net/note/delete/73678/spam
Del: non-english -- https://master.php.net/note/delete/73678/non-english
Del: in docs -- https://master.php.net/note/delete/73678/in+docs
Del: other reasons-- https://master.php.net/note/delete/73678
Reject -- https://master.php.net/note/reject/73678
Search -- https://master.php.net/manage/user-notes.php