打你一下

TP自动提取关键词

protected function _before_insert(&$data, $option) {
        $data['create_time'] = time();
        $str = I('post.title');
        $char = "。、!?:;﹑,•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐­˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()";
        $pattern = array(
            "/[[:punct:]]/i", //英文标点符号
            '/[' . $char . ']/u', //中文标点符号
            '/[ ]{2,}/'
        );
        $str = preg_replace($pattern, '', $str);
        import("Org.Util.Phpanalysis");
        $pa = new \PhpAnalysis('utf-8', 'utf-8', false);
        $pa::$loadInit = false;
        $pa->LoadDict();
        $pa->SetSource($str);
        $pa->unitWord = true;
        $pa->StartAnalysis(true);
        $tags = $pa->GetFinallyResult();
        $str = str_replace(" ", ",", $tags);
        $str = ltrim($str, ",");//去掉首个字符,rtrim是去掉末尾字符
        $data['trade_key'] = $str;
    }

posted on 2017-06-22 13:27  打你一下  阅读(228)  评论(0编辑  收藏  举报

导航