小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

php自動(dòng)搜索關(guān)鍵字

 丶平上 2019-06-24
/**
* 自動(dòng)識(shí)別關(guān)鍵詞方法
* @param String $text 需要查詢的文本
* @param String $keysStr 用來標(biāo)記的關(guān)鍵詞字符串
* @param Int $similar 可以插入的關(guān)鍵詞相似度 默認(rèn)60%
* @return Array
*/
function searchKeys($text = "",$keysStr = "",$similar = ""){
//關(guān)鍵詞相似度
$similar = $similar == null ? 60 : $similar;
//組裝特殊字符,并替換
$Exp = str_replace(array(":","。",'"',"/","-","_","=","~","`","(",")","*","&","^","%","$","#","@","!",":",":","、","“",".","”",";","】","【","[","]","|",'\/'," "," ","'",""","<",">","?","/","]","[","!","@","#","$","%","^","&","*","(",")","_","+","=","-","/","*","-","+",".","`","~",";",":","'",""","|","\"),"",strip_tags($text));
$Exps = str_replace(",",",",$Exp);

//將切割的文字組裝成數(shù)組
$textArr_1D = explode(",",$Exps);
//將內(nèi)容轉(zhuǎn)換成二維數(shù)組
$textArr_2D = array();
foreach($textArr_1D as $val){
$textArr_2D[]['text'] = $val;
}
//去除關(guān)鍵詞的最后一位
$keysStr = substr($keysStr,0,strlen($keysStr)-1);
//切割關(guān)鍵詞成一維數(shù)組
$keysArr_1D = explode(",",$keysStr);
//轉(zhuǎn)換成二維數(shù)組
$keysArr_2D = array();
foreach ($keysArr_1D as $val) {
$keysArr_2D[]['keys'] = $val;
}
//開始匹配關(guān)鍵詞
foreach ($textArr_2D as $t_k => $t_v) {
foreach ($keysArr_2D as $k_k => $k_v) {
//判斷關(guān)鍵詞不為空
if($k_v['keys'] != ""){
//根據(jù)文本相似度
if(similar_text($t_v['text'],$k_v['keys'],$percent)){
//當(dāng)相似度大于等于**時(shí)插入到數(shù)組
if($percent >= $similar){
$data[]['keys'] = $k_v['keys'].$percent."%";
}
}
//不區(qū)分大小寫尋找相同字符
if(stristr($t_v['text'],$k_v['keys']) != false){
$data[]['keys'] = $k_v['keys'];
}
//區(qū)分大小寫尋找相同字符
if(strpos($t_v['text'],$k_v['keys']) != false){
$data[]['keys'] = $k_v['keys'];
}
}
}
}
return array_unique_fb($data);
}
/**
* 數(shù)組去重方法
*/
function array_unique_fb($array2D){
foreach ($array2D as $v){
$v = join(",",$v); //降維,也可以用implode,將一維數(shù)組轉(zhuǎn)換為用逗號(hào)連接的字符串
$temp[] = $v;
}
$temp = array_unique($temp); //去掉重復(fù)的字符串,也就是重復(fù)的一維數(shù)組
foreach ($temp as $k => $v){
$temp[$k] = explode(",",$v); //再將拆開的數(shù)組重新組裝
}
return $temp;
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多