Jump to content

Recommended Posts

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');

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'));

 

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.