How to implement all word substitutions in a namespace
DataCleaner.inc.php:
PHP Code
"Shortsighted", "moronic" = "unreasonable", "insane" and "illogical" ); Remove Bad Words foreach ($badwords as $key = $value) { if (Strpos ($text, $key)!== false) return str _replace ($key, $value, $text);}} ? >
Library.inc.php:
PHP Code
index.php:
PHP Code
", $title); $title = $data->removeprofanity ($title); printf ("Title after Data::clean:%s
", $title); $title = $library->filtertitle ($title); printf ("Title after Library::clean:%s
", $title);? >
Output:
Title before Filters:the moronic Sun Also rises idiotic insane
Title after Data::clean:the moronic Sun Also rises shortsighted insane
Title after Library::clean:the moronic Sun Also rises shortsighted insane
How to implement all the
"Idiotic" = "shortsighted",
"Moronic" = "unreasonable",
"Insane" = "illogical"
These words are replaced with the corresponding words??
------Solution--------------------
foreach ($badwords as $key = = $value) {
if (Strpos ($text, $key)!== false)
Return Str_replace ($key, $value, $text);
}
=================
Revision changed to
Return Strtr ($text, $badwords);