PHP jieba分词


jieba(结巴)中文分词拓展包安装

composer require fukuball/jieba-php:dev-master

分词使用

use Fukuball\Jieba\Jieba;
use Fukuball\Jieba\Finalseg;
ini_set('memory_limit', '2048M');
Jieba::init();
Finalseg::init();
$strArr= Jieba::cut("旅美大熊猫丫丫落地后被运送至隔离检疫圈舍饲养员在精心喂食丫丫帮助丫丫适应新的居住环境");
var_dump($strArr);
array(23) {                
  [0] => string(6) "旅美"  
  [1] => string(9) "大熊猫"
  [2] => string(6) "丫丫"  
  [3] => string(6) "落地"  
  [4] => string(3) "后"    
  [5] => string(3) "被"    
  [6] => string(6) "运送"  
  [7] => string(3) "至"    
  [8] => string(6) "隔离"  
  [9] => string(6) "检疫"
  [10] => string(6) "圈舍"
  [11] => string(9) "饲养员"
  [12] => string(3) "在"
  [13] => string(6) "精心"
  [14] => string(6) "喂食"
  [15] => string(6) "丫丫"
  [16] => string(6) "帮助"
  [17] => string(6) "丫丫"
  [18] => string(6) "适应"
  [19] => string(3) "新"
  [20] => string(3) "的"
  [21] => string(6) "居住"
  [22] => string(6) "环境"
}

注意:这里要写上ini_set('memory_limit', '2048M');内存设置,不设置可能出现内存不够无法运行


4月29日,星期六,在这里每天60秒读懂世界!

4月28日,星期五,在这里每天60秒读懂世界!

评 论
更换验证码