加入收藏 | 设为首页 | 会员中心 | 我要投稿 鹤壁站长网 (https://www.0392zz.cn/)- 分布式云、存储数据、视频终端、媒体处理、内容创作!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php除去字串中的重复词,生成索引字符串

发布时间:2022-06-17 08:41:43 所属栏目:PHP教程 来源:互联网
导读: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; i
  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;//开源代码phpfensi.com
          }
        }
      }
      return trim($okstr);
    }

(编辑:鹤壁站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读