求php的分割标题 并且保存到某字段中的代码,该如何解决

WBOY
Release: 2016-06-13 13:37:22
Original
839 people have browsed it

求php的分割标题 并且保存到某字段中的代码
我想给一个php的小程序加一个低级关键词功能,就像动易采集时候的分词效果一样,例如标题是:我从未见过奥特曼

动易采集自动分词的结果是:我从|从未|未见|见过|过奥|奥特|特曼


我自己试了 php的分割函数,但是分割后都是很痛苦的数组,郁闷,求指点!

我没php基础 只是看了一点小介绍!

我这样想的

$title=我从未见过奥特曼

$keyword = str_split($title,1);

但是这样分割后都是数组,而且这样分割好貌似就变成了:我|从|未|见|过|奥|特|曼

求指点,怎么才能像动易采集自动生成关键词那样的生成结果呢!

------解决方案--------------------
先来一个。注意是utf-8编码下。

PHP code

$title='我从未见过奥特曼';
$len= mb_strlen($title,'utf-8');
$l=0;
while($l<font color="#e78608">------解决方案--------------------</font><br>你可以安装SCWS中文分词系统,有Windows和linux两种版本,可作为php的扩展使用。安装后,用phpinfo查看,如果出现scws,则代表成功。<br>例子:<br>$sh = scws_open();<br>scws_set_charset($sh, 'gbk');<br>scws_set_multi($sh,SCWS_MULTI_SHORT | SCWS_MULTI_DUALITY | SCWS_MULTI_ZMAIN | SCWS_MULTI_ZALL);<br>$text = "我从未见过奥特曼";<br>scws_send_text($sh, $text);<br>$top = scws_get_tops($sh, 10);<br>print_r($top);<br> <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!