亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從文本 php 中提取關鍵字

從文本 php 中提取關鍵字

PHP
MMTTMM 2021-10-08 13:11:38
我正在嘗試從使用所見即所得的描述輸入中提取相關關鍵字,使用多語言英語/阿拉伯語......使用以下功能,但它沒有完成我想要的任務。看看我正在使用的功能:   function extractKeyWords($string) {     mb_internal_encoding('UTF-8');     $stopwords = array();     $string = preg_replace('/[\pP]/u', '', trim(preg_replace('/\s\s+/iu', '', mb_strtolower($string))));     $matchWords = array_filter(explode(' ',$string) , function ($item) use ($stopwords) { return !($item == '' || in_array($item, $stopwords) || mb_strlen($item) <= 2 || is_numeric($item));});     $wordCountArr = array_count_values($matchWords);     // <p><p>     arsort($wordCountArr);     return array_keys(array_slice($wordCountArr, 0, 10));   }
查看完整描述

2 回答

?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

弄清楚了 !謝謝


function generateKeywords($str)

        {

            $min_word_length = 3;

            $avoid = ['the','to','i','am','is','are','he','she','a','an','and','here','there','can','could','were','has','have','had','been','welcome','of','home','&nbsp;','&ldquo;','words','into','this','there'];

            $strip_arr = ["," ,"." ,";" ,":", "\"", "'", "“","”","(",")", "!","?"];

            $str_clean = str_replace( $strip_arr, "", $str);

            $str_arr = explode(' ', $str_clean);

            $clean_arr = [];

            foreach($str_arr as $word)

            {

                if(strlen($word) > $min_word_length)

                {

                    $word = strtolower($word);

                    if(!in_array($word, $avoid)) {

                        $clean_arr[] = $word;

                    }

                }

            }

            return implode(',', $clean_arr);

        }


查看完整回答
反對 回復 2021-10-08
  • 2 回答
  • 0 關注
  • 133 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號