sneamia Posted March 6, 2008 Share Posted March 6, 2008 if (!empty($_POST['query'])) { $dict = file_get_contents('sowpods.txt'); // Get contents of dictionary in $dict. if (strpos($dict, "\n" . strtoupper(htmlentities($_POST['query'])) . "\n") === false) { echo '<div id="no"><p>No</p></div>'; } else { echo '<div id="yes"><p>Yes</p></div>'; } } The SOWPODS dictionary is arranged like: AARDVARK AARDVARKS AARDWOLF AARDWOLVES A \n before each word, and a \n after. How would you optimize this code snippet? Link to comment https://forums.phpfreaks.com/topic/94806-optimizing-this-snippet/ Share on other sites More sharing options...
fnairb Posted March 7, 2008 Share Posted March 7, 2008 If you are running on a UNIX system it may be faster to use a system call and grep the file. Link to comment https://forums.phpfreaks.com/topic/94806-optimizing-this-snippet/#findComment-485779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.