PHP脏话处理

Category : PHP

在开发过程中,经常会遇到需要处理脏字的问题,这里提供了一种简单通用的解决办法.
首先,把所有需要过滤的脏字存成字符串的形式,每个脏字之间用','来分隔,比如说"fuck,shit".
然后,用explode()来将字符串转换成数组,并用str_replace()来进行脏字的替换.
PHP代码:

<?php
function remove_bad_words($words){
    $bad_words = "shit,fuck";
    $array = explode(',',$bad_words);
    foreach ($array as $one) {
        $words = str_replace($one,'**',$words);
    }
    return $words;
}
$original_words = "shit , fuck you";
$modified_words = remove_bad_words($words);
print_r($modified_words);
?>

Tags :  PHP 

Published by 2008-12-10 17:27:14 | Views : 298 | Comments : 45


Comments

isdbykrggu said :

PT6wcn rbmxvjlesxdc, [url=http://htoyazmdchxi.com/]htoyazmdchxi[/url], [link=http://mfkxqqozlhzo.com/]mfkxqqozlhzo[/link], http://tlcbljpaumcp.com/

Published by : 2009-10-24 17:08:00

Channel said :

You can place the order online. For more information kindly visit www. levitra 8]] cialis :O valium %)

Published by : 2009-11-05 11:37:56

vonny-thm said :

levitra 91067 ambien 8-[ acomplia umfthb

Published by : 2009-11-05 23:07:56

Triangle said :

However you never know what you will become sensitive to. levitra online 8OO buy valium >:[[ accutane 1663

Published by : 2009-11-06 00:08:36

Triangle said :

However you never know what you will become sensitive to. levitra online 8OO buy valium >:[[ accutane 1663

Published by : 2009-11-06 00:08:37

Aastrom said :

accutane vhx buy propecia smfws

Published by : 2009-11-24 07:20:26

lastupdated1 said :

accutane iwfx buy propecia %-PP

Published by : 2009-11-24 08:09:19

arialnormal said :

acomplia 550762 xanax 5900

Published by : 2009-12-21 03:43:53

Formatvorlage2 said :

levitra >:]]] acomplia 652257 tramadol :-DD

Published by : 2009-12-21 05:55:20

text111 said :

phentermine sdr

Published by : 2009-12-28 03:59:37

 *(required)

 (won't be displayed)