|
@@ -16,7 +16,7 @@ class Keyworld
|
|
|
* @param string $string 要过滤的内容
|
|
|
* @return string $log 处理结果
|
|
|
*/
|
|
|
- public static function sensitive($string){
|
|
|
+ public static function sensitive_old($string){
|
|
|
$count = 0; //违规词的个数
|
|
|
$sensitiveWord = ''; //违规词
|
|
|
$stringAfter = $string; //替换后的内容
|
|
@@ -46,6 +46,28 @@ class Keyworld
|
|
|
return $stringAfter;
|
|
|
}
|
|
|
|
|
|
+ public static function sensitive($string){
|
|
|
+ if(empty($string)){
|
|
|
+ return $string;
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = config('keyworld'); //定义敏感词数组
|
|
|
+ $replaceArray = []; //含有的违禁词集合
|
|
|
+
|
|
|
+ foreach($list as $key => $word){
|
|
|
+ if(empty($word)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $start = strpos($string,$word);
|
|
|
+ if($start !== false){
|
|
|
+ $replaceArray[$word] = '*';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $stringAfter = strtr($string, $replaceArray); //结果替换
|
|
|
+ return $stringAfter;
|
|
|
+ }
|
|
|
+
|
|
|
public static function checkAction($data,$fields){
|
|
|
//$string = 'likeyou小白喜欢小黑爱着的大黄'; //要过滤的内容
|
|
|
foreach($data as $key => $string){
|