#!/home/c/s/cs50/pub/local/i386/php/bin/php 0)) { // append character to word $word .= $c; $index++; // ignore alphabetical strings too long to be words if ($index >= LENGTH) { // consume remainder of alphabetical string while (($c = fgetc($fp)) !== FALSE && preg_match("/[a-zA-Z]/", $c)); // prepare for new word $index = 0; $word = ""; } } // ignore words with numbers (like MS Word) else if (ctype_digit($c)) { // consume remainder of alphabetical string while (($c = fgetc($fp)) !== FALSE && ctype_digit($c)); // prepare for new word $index = 0; $word = ""; } // we must have found a whole word else if ($index > 0) { // update counter $words++; // check word's spelling $before = microtime(TRUE); $misspelled = !check($word); $after = microtime(TRUE); // update benchmark $lookups += $after - $before; // print word if misspelled if ($misspelled) { print("$word\n"); $misspellings++; } // prepare for next word $index = 0; $word = ""; } } // close file fclose($fp); // determine dictionary's size $before = microtime(TRUE); $n = size(); $after = microtime(TRUE); // calculate time to determine dictionary's size $sizing = $after - $before; // report benchmarks printf("\nWORDS MISSPELLED: %d\n", $misspellings); printf("WORDS IN DICTIONARY: %d\n", $n); printf("WORDS IN FILE: %d\n", $words); printf("STARTUP TIME: %f\n", $startup); printf("LOOKUP TIME: %f\n", $lookups); printf("SIZING TIME: %f\n", $sizing); printf("TOTAL TIME: %f\n\n", $startup + $lookups + $sizing); ?>