0 Replies - 1621 Views - Last Post: 03 January 2011 - 03:44 AM

#1 bizzehdee  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 54
  • Joined: 06-April 08

PHP Keyword Generator

Posted 03 January 2011 - 03:44 AM

Description: Generates a keyword list from a set of text, and grades the keywords based on number of occurrences. Also supports filter words so words such as "a" "and" and "the" can be filtered out
function get_filter_words() {
  $words = array('000', ..., 'zwölf' );
  return $words;
}

function is_valid_keyword($word) {
  $common_words = get_filter_words();

  return (strlen($word) >= 3 && !in_array($word, $common_words)) ? true : false;
}

function get_valid_keywords($words) {
  $word_arr = array();
  $word_ret = array();

  if(!is_array($words)) {
    $word_arr = preg_split("/[s,]/", $words, -1, PREG_SPLIT_NO_EMPTY);
  }

  foreach($word_arr as $word) {
    if(is_valid_keyword($word)) {
      if(empty($word_ret[$word])) {
        $word_ret[$word] = 1;
      } else {
        $word_ret[$word]++;
      }
    }
  }

  arsort($word_ret, SORT_NUMERIC);

  return $word_ret;
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1