Jnerocorp Posted September 27, 2009 Share Posted September 27, 2009 Hello, I have a list of almost 900 words the list looks like this in a text file a able about account acid across act addition adjustment advertisement after again against agreement air all almost among amount amusement and angle angry animal answer ant any apparatus apple approval arch argument arm army art is there a script to turn a list like that into an array like this array('a','able','about','account','acid','across','act','addition'); Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/ Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 file() does exactly this, takes the contents of a file and stores each line in an element of an array. $array = file('sometextfile.txt'); Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925609 Share on other sites More sharing options...
redarrow Posted September 27, 2009 Share Posted September 27, 2009 whale that was grate read cheers alexWD grate function. http://uk3.php.net/manual/en/function.file.php Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925615 Share on other sites More sharing options...
.josh Posted September 27, 2009 Share Posted September 27, 2009 note: from a text file, you will have the \n (and possibly \r also) newline chars after each word, so you will want to trim each value in the array. You can do all of them in one go using array_map like this: $array = array_map('trim', file('sometextfile.txt')); Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925623 Share on other sites More sharing options...
Jnerocorp Posted September 27, 2009 Author Share Posted September 27, 2009 thank you very much also do u know where i can get a large text file list with just english words in it 1 word per line The largest list i could find was one with about 900 words in it Thanks, John Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925624 Share on other sites More sharing options...
.josh Posted September 27, 2009 Share Posted September 27, 2009 I have a text file that has like 225,000 words or so. It is exhaustive and includes many things that are not real "words" per se (like, it has names, proper nouns, etc.. and even a couple acronyms I think...) edit: Actually I have 2 files: 1 with the words and one with the words and their part of speech (like "dolphin\N" N = Noun) Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925626 Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 Well, a quick google search returned this: http://www.mieliestronk.com/wordlist.html It has 58,000 words. Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925627 Share on other sites More sharing options...
Jnerocorp Posted September 27, 2009 Author Share Posted September 27, 2009 Thats fine if you wouldnt mind letting me using may i have a copy of it? Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925628 Share on other sites More sharing options...
.josh Posted September 27, 2009 Share Posted September 27, 2009 I'll send it to the email in your profile Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925631 Share on other sites More sharing options...
redarrow Posted September 27, 2009 Share Posted September 27, 2009 And me big boy lol cheers....... Quote Link to comment https://forums.phpfreaks.com/topic/175661-solved-help-turning-list-of-words-into-an-array/#findComment-925633 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.