2
<?php
header("Content-type:text/html;charset=utf-8");
 
$keywords = "什么是快乐星球?";
 
for ($i=0; $i <= mb_strlen($keywords); $i++) { 
    // 将关键词的第一个字分割掉
    $a = mb_substr($keywords,$i,mb_strlen($keywords),'utf-8');
    // 提取每一段关键词的前2个字作为新的关键词,每个关键词进行一次查询,将查询结果加入数组
    // 最后返回数组就是最终的查询结果
    $b = mb_substr($a,0,2,'utf-8');
    echo $b."<br/>";
}
?>

Preprocessing keywords

The first word of the keyword starting from 0 is truncated as a new preprocessing keyword.
image.png

Participle

Then, each keyword with the first word truncated is intercepted and the first two words are used as independent keywords, namely word segmentation.
image.png

Finally, query the database for each keyword. If the query finds the result, it will be added to an array. If there is no result, it will not be added to the array. All the keywords will be checked all the time and the result will be output.

Web:www.likeyuns.com
Author:TANKING
WeChat:sansure2016


TANKING
4.8k 声望493 粉丝

热爱分享,热爱创作,热爱研究。