除去字串中的重复词,生成索引字符串_PHP教程
时间:2021-07-01 10:21:17
帮助过:9人阅读
除去字串中的重复词,生成索引字符串
//--------------------------------------------------
function GetIndexText($okstr,$ilen=-1)
{
if($okstr=="") return "";
$ws = explode(" ",$okstr);
$okstr = "";
$wks = "";
foreach($ws as $w)
{
$w = trim($w);
//排除小于2的字符
if(strlen($w)<2) continue;
//排除数字或日期
if(!ereg("[^0-9:-]",$w)) continue;
if(strlen($w)==2&&ord($w[0])>0x80) continue;
if(isset($wks[$w])) $wks[$w]++;
else $wks[$w] = 1;
}
if(is_array($wks))
{
arsort($wks);
if($ilen==-1)
{ foreach($wks as $w=>$v) $okstr .= $w." "; }
else
{
foreach($wks as $w=>$v){
if((strlen($okstr)+strlen($w)+1)<$ilen) $okstr .= $w." ";
else break;
}
}
}
return trim($okstr);
}
http://www.bkjia.com/PHPjc/444979.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444979.htmlTechArticle除去字串中的重复词,生成索引字符串 //-------------------------------------------------- function GetIndexText($okstr,$ilen=-1) { if($okstr==) return ; $ws = explod...