mapleleaf Posted June 18, 2010 Share Posted June 18, 2010 $file = file_get_contents("en-GB-oed-wlist.txt"); if(!strpos($file, $_GET['word'])) { echo "Word not found!"; }else{ echo $_GET['word'].' is ok'; } I need to create a basic spell checker for UK English so color should not show up when Colorado is in the word list file which it will with the above code. Any help much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/205198-find-words-in-file-but-not-partial-words/ Share on other sites More sharing options...
ram4nd Posted June 18, 2010 Share Posted June 18, 2010 Can we see the file. OMG... Quote Link to comment https://forums.phpfreaks.com/topic/205198-find-words-in-file-but-not-partial-words/#findComment-1074084 Share on other sites More sharing options...
Alex Posted June 18, 2010 Share Posted June 18, 2010 You can use preg_match along with the \b modifier. if(preg_match("~\b{$_GET['word']}\b~", $file)) { // Found } else { // Not found } Quote Link to comment https://forums.phpfreaks.com/topic/205198-find-words-in-file-but-not-partial-words/#findComment-1074092 Share on other sites More sharing options...
mapleleaf Posted June 18, 2010 Author Share Posted June 18, 2010 Alex that is exactly the regex I needed thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/205198-find-words-in-file-but-not-partial-words/#findComment-1074099 Share on other sites More sharing options...
ram4nd Posted June 18, 2010 Share Posted June 18, 2010 How can you remove color with that regex? This really isn't about the color right? Quote Link to comment https://forums.phpfreaks.com/topic/205198-find-words-in-file-but-not-partial-words/#findComment-1074103 Share on other sites More sharing options...
Alex Posted June 18, 2010 Share Posted June 18, 2010 How can you remove color with that regex? This really isn't about the color right? You misunderstood the question. mapleleaf was simply asking how to search a string of words for a certain word and did not want, for example, "Color" to match because "Colorado" was in the string. Quote Link to comment https://forums.phpfreaks.com/topic/205198-find-words-in-file-but-not-partial-words/#findComment-1074104 Share on other sites More sharing options...
mapleleaf Posted June 18, 2010 Author Share Posted June 18, 2010 I think my own question was confused as I really need to be able to run a function on a body of text not just a word. I was starting small Any ideas for that most welcome and thanks for the help so far. Here is the format of the file: coloratura's colorimeter colorimeters colorimeter's colorimetric colorimetry colossal colossally Colosseum colossi colossus colossus's colostomies colostomy colostomy's colostrum colostrums colostrum's colour colourant colourants colourant's colouration colourations colouration's colour-blind colour-blindness colour-blindness's colour-code It was too big to upload Quote Link to comment https://forums.phpfreaks.com/topic/205198-find-words-in-file-but-not-partial-words/#findComment-1074139 Share on other sites More sharing options...
Alex Posted June 18, 2010 Share Posted June 18, 2010 What exactly do you need to do? Quote Link to comment https://forums.phpfreaks.com/topic/205198-find-words-in-file-but-not-partial-words/#findComment-1074140 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.