多个字符过滤
preg_match:
if(preg_match('/(词1|词2|词3)+/', $string)){ return false; }
str_replace:
$str=str_replace("select","",$str);
preg_replace:
$str = preg_replace(array('/深圳市/', '/深圳/'),"",$str);
$string = 'The quick brown fox jumped over the lazy dog.'; $patterns = array(); $patterns[0] = '/quick/'; $patterns[1] = '/brown/'; $patterns[2] = '/fox/'; $replacements = array(); $replacements[2] = 'bear'; $replacements[1] = 'black'; $replacements[0] = 'slow'; echo preg_replace($patterns, $replacements, $string); ?> 以上例程会输出: The bear black slow jumped over the lazy dog. ksort($patterns); ksort($replacements); echo preg_replace($patterns, $replacements, $string); 以上例程会输出: The slow black bear jumped over the lazy dog
PHP学习:字符串操作和正则表达式:http://www.cnblogs.com/xbf321/archive/2011/09/07/string-in-php.html