$three_years,]); $cookie_username = ""; if(isset($_COOKIE['username'])) { $cookie_username=$_COOKIE['username']; //3.check if it's a word to prevent random guessing letters aeiou $word_found = db_does_word_exists($input_text_filtered); $user_info = db_get_all_account_info($cookie_username); if($word_found == true && count($user_info) > 0) { $correct_word = $user_info[0]['word_text']; $correct_word_chars = str_split($correct_word,1); //split input text into characterss $input_chars = str_split($input_text_filtered, 1); //user input cat, match, string //word spurred, 7 characters, so pad string 7 characters //need to pad str str_pad($input, 10) //correct word == comma //guesses = omar_ , crane, //highlite correct position and letter green //count number of letters //comma vs apple vs mocko //c1,o1,m1,m2,a1 a1,p1,p2,l1,e1, m1 o1 c1 k1 o2 //mocko o highlite first instance but not second //can now check if a1 there , but not in position put yellow //for each letter in usersub //if position and char same in correctword //green //if not check what character number instance is usersub and correct word //if both equal put yellow //if not make black $attempt_array = array(); //new if($input_text_filtered == $correct_word) { //user entered correct word db_insert_attempt($user_info[0]['user_id'], $user_info[0]['last_word_id'], $input_text_filtered, 'GGGGGG');//6 Gs $response_json = array('response' => 'word is correct'); //echo json_encode($response_json); } else { //user entered incorrect word, log attempt $response_json = array('response' => 'word is incorrect'); //echo json_encode($response_json); //highlite all correct characters first for($x = 0; $x < strlen($correct_word); $x++) { $user_char = $input_chars[$x]; $correct_word_char = $correct_word_chars[$x]; if ($user_char == $correct_word_char) { $attempt_array[] = array($user_char, 'CORRECT'); }else{ $attempt_array[] = array($user_char, 'INCORRECT'); } } //highlite all possible characters wrong position for($x = 0; $x < strlen($input_text_filtered); $x++) { $user_char = $input_chars[$x]; $attempt_match = $attempt_array[$x][1]; $number_instance = getNumberOfCharInstanceInString($user_char, $input_text_filtered); if($attempt_match == 'INCORRECT') { for($z = 0; $z < strlen($correct_word); $z++) { $correct_word_char = $correct_word_chars[$z]; if ($user_char == $correct_word_char) { //first check if position //cehck duplicates TODO if($attempt_array[$x][1]=='INCORRECT') { $attempt_array[$x][1]='POSSIBLE'; } } } } } //encode char state GPI good possible incorrect $character_state = ""; foreach($attempt_array as $an_attempt) { if($an_attempt[1] == 'CORRECT'){ $character_state = $character_state."G"; }elseif($an_attempt[1] == 'POSSIBLE'){ $character_state = $character_state."P"; }else{ $character_state = $character_state."I"; } }//foreach //update db db_insert_attempt($user_info[0]['user_id'], $user_info[0]['last_word_id'], $input_text_filtered, $character_state); }//else $array_attempts = db_get_all_account_info($cookie_username); echo json_encode($array_attempts); }//if }//function ?>