2009-08-27 48 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);