2009-08-27 45 views
2

有誰知道一個可用的PHP函數需要一段文本,比如說幾百個字,並生成一組關鍵字? IE瀏覽器。最重要的,經常發生的獨特術語?字符串中的關鍵字

感謝 菲利普

回答

7

沒有這樣的功能存在(是神奇的,如果它所做的那樣),而是開始做了,你可以做到以下幾點:

  1. Split在空間中的文本, 生產一組單詞。
  2. 刪除stop-words和 不必要的標點和符號(可能使用regular expressions - 參見preg_replace)。
  3. 計數的 每個字的其餘陣列中, OCCURENCES的數量和它在頻率 的排列(因此最經常存在的字是在所述第一偏移,即$words[0])。
  4. 使用array_unique刪除 重複項,從而生成排序爲 的唯一關鍵字的數組 發生的頻率。
+0

你打我吧。 – 2009-08-27 01:33:54

0

像這樣的事情可能做的伎倆:

$thestring = 'the most important, frequently occuring unique terms?'; 
$arrayofwords = explode(" ", $thestring); 
echo print_r($arrayofwords); 

你也可以更換新的逗號「」爲一個空白,所以你得到乾淨的關鍵字。

$thestring = 'the most important, frequently occuring unique terms?'; 
$cleaned_string = str_replace(",", "", "$thestring"); 
$arrayofwords = explode(" ", $cleaned_string); 
echo print_r($arrayofwords);