How to implement all word substitution in a namespace

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