In the namespace, how does one replace all words with DataCleaner. inc. php: PHPcode & lt ;? PhpnamespaceDataCleaner; classClean {functionRemoveProfanity ($ text) {how to replace all words in the namespace
DataCleaner. inc. php:
PHP code
"shortsighted", "moronic" => "unreasonable", "insane" => "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 inclusighted insane
Title after Library: Clean: The moronic sun also rises inclusighted insane
How to implement
"Idiotic" => "inclusighted ",
"Moronic" => "unreasonable ",
"Insane" => "illogical"
All these words are replaced with corresponding words ??
------ Solution --------------------
Foreach ($ badwords as $ key => $ value ){
If (strpos ($ text, $ key )! = False)
Return str_replace ($ key, $ value, $ text );
}
========================
Change
Return strtr ($ text, $ badwords );