common.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }
  34. /**
  35. * 上传路径转化,默认路径 UPLOAD_PATH
  36. * $type 类型
  37. */
  38. function makePathToUrl($path,$type = 2)
  39. {
  40. $path = DS.ltrim(rtrim($path));
  41. switch ($type){
  42. case 1:
  43. $path .= DS.date('Y');
  44. break;
  45. case 2:
  46. $path .= DS.date('Y').DS.date('m');
  47. break;
  48. case 3:
  49. $path .= DS.date('Y').DS.date('m').DS.date('d');
  50. break;
  51. }
  52. if (is_dir(ROOT_PATH.UPLOAD_PATH.$path) == true || mkdir(ROOT_PATH.UPLOAD_PATH.$path, 0777, true) == true) {
  53. return trim(str_replace(DS, '/',UPLOAD_PATH.$path),'.');
  54. }else return '';
  55. }
  56. // 过滤掉emoji表情
  57. function filterEmoji($str)
  58. {
  59. $str = preg_replace_callback( //执行一个正则表达式搜索并且使用一个回调进行替换
  60. '/./u',
  61. function (array $match) {
  62. return strlen($match[0]) >= 4 ? '' : $match[0];
  63. },
  64. $str);
  65. return $str;
  66. }