I have a list of several thousand words that I want to use to create a list of all possible combinations of those words (only two words in each combination though).



word1word4 and so on.

I would usually do this in excel but it is proving too slow, so I plan to try in PHP.

I don't have much of an idea on how to approach this, does anyone have any suggestions.

Thanks in advance

Recommended Answers

All 2 Replies

It will be slow in any programing language.
You can try to put that words in memory but I don't know if you can do that. Maybe your file is too big for that.
Then combinate one word with others.
When you finish that you need to know do you need word1word2 and word2word1.
If you don't need second thing then after doing everything with word1 + wordN
you can delete word1 that will speed up a little. But as I said I think it will be slow in any programing language you do it...
And yes please define "SLOW".
Regards, Mike.

You should load in all the words in a PHP array.

As milil suggests, this will take up a lot of memory. Basically consider the size of your text file, and expect to need this much memory (RAM) on the machine that will run this script. In addition you will need to set the php directive for maximum allowed memory usage, do this with the function ini_set.

Set up a loop that will combine all your words, and then output that word to a text file or flush it to echo (display on screen). If you have enough memory and also need to post process the words, store them in memory, that's faster.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.