<?php
include ("../includes/db_functions.inc.php");

function commonWords($string){
    $stopWords = array( ' the ',' of ',' and ',' a ',' to ',' in ',' is ',' you ',' that ',' it ',' he ',' was ',' for ',' on ',' are ',' as ',' with ',' his ',' they ',' I ',' at ',' be ',' this ',' have ',' from ',' or ',' one ',' had ',' by ',' word ',' but ',' not ',' what ',' all ',' were ',' we ',' when ',' your ',' can ',' said ',' there ',' use ',' an ',' each ',' which ',' she ',' do ',' how ',' their ',' if ',' will ',' up ',' other ',' about ',' out ',' many ',' then ',' them ',' these ',' so ',' some ',' her ',' would ',' make ',' like ',' him ',' into ', 'time ',' has ',' look ',' two ',' more ',' write ',' go ', 'see ',' number ', 'no ', ' way ',' could ',' people ',' my ',' than ',' first ',' water ',' been ',' call ',' who ',' oil ',' its ', ' now ',' find ',' long ',' down ',' day ',' did ',' get ',' come ',' made ',' may ',' part ',' click ');
    $punct = array('.',';','?','!',':');
	$string = str_replace($punct, ' ', $string);
	$string = preg_replace('/ss+/i', '', $string);
    $string = trim($string); // trim the string
    $string = preg_replace('/[^a-zA-Z0-9 -]/', '', $string); // only take alphanumerical characters, but keep the spaces and dashes too…
    $string = strtolower($string); // make it lowercase
 
    preg_match_all('/([a-z]*?)(?=s)/i', $string, $matchWords);
    $matchWords = $matchWords[0];
    foreach ( $matchWords as $key=>$item ) {
        if ( $item == '' || in_array(strtolower($item), $stopWords) || strlen($item) <= 3 ) {
            unset($matchWords[$key]);
        }
    }
    $wordCountArr = array();
    if ( is_array($matchWords) ) {
        foreach ( $matchWords as $key => $val ) {
            $val = strtolower($val);
            if ( isset($wordCountArr[$val]) ) {
                $wordCountArr[$val]++;
            } else {
                $wordCountArr[$val] = 1;
            }
        }
    }
    arsort($wordCountArr);
   $wordCountArr = array_slice($wordCountArr, 0, 40);
    return $wordCountArr;		
}
$query = yasDB_select("SELECT `name`, `description` FROM `mochigames` WHERE `categories` LIKE '%shooting%'");
$data = '';
while ($text = $query->fetch_array(MYSQLI_ASSOC)) {
	$data = $data . ' ' . $text['title'] . ' ' . $text['description'];
}
$words = commonWords($data);
echo implode(',', array_keys($words));

?>