common.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // 应用公共文件
  12. /**
  13. * 敏感词过滤
  14. *
  15. * @param string
  16. * @return string
  17. */
  18. function sensitive_words_filter($str)
  19. {
  20. if (!$str) return '';
  21. $file = ROOT_PATH. PUBILC_PATH.'/static/plug/censorwords/CensorWords';
  22. $words = file($file);
  23. foreach($words as $word)
  24. {
  25. $word = str_replace(array("\r\n","\r","\n","/","<",">","="," "), '', $word);
  26. if (!$word) continue;
  27. $ret = preg_match("/$word/", $str, $match);
  28. if ($ret) {
  29. return $match[0];
  30. }
  31. }
  32. return '';
  33. }