How to replace all words in a namespace

Source: Internet
Author: User
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.