Random Word Combination Generator

I am looking for php code to create a random combination of 2 words.  I also need a dictionary to use to pull the words form.  The reason I posted within the php coding section is that the php code needs to know NOT to create a 'bad' combination.  Meaning if the dictionary has the words 'screw', 'tree' and 'me' I do not want a result of 'ScrewMe' but 'TreeScrew' would be okay, etc.  I have not been able to find a dictionary which will never result in a bad combination.  I'm guessing I'll need a dictionary which has words ranked and the PHP knows which words can go together and which can not.

Thanks!
dotcomexecAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TeRReFCommented:
Depends on the size of the dictionary, but if it's not to big, you could use 2 arrays to do the trick, one with the dictionary, one with 'naughty' words like so:

<?php
//This depends a bit on the size of the dictionary, but if it is not too big, you could use 2 arrays like so:
$dictionary = array("Screw", "Tree", "Me", "Sky", "Road", "etc.");
$naughtywords = array("ScrewMe", "etc.");

//Create a function like so and use it to get 2 words from $dictionary:
function getwords($dictionary, $naughtywords) {
    $word1 = "blah";
    $word2 = "blah";
    while($word1 == $word2) {
        $word1 = $dictionary[rand(0, count($dictionary) -1)];
        $word2 = $dictionary[rand(0, count($dictionary) -1)];
    }
    $finalword = $word1.$word2;
    if (in_array($finalword, $naughtywords))
        getwords();
    return $finalword;
}

//Then use it like so:
$combiword = getwords($dictionary, $naughtywords);
print "Combiword: ".$combiword;
?>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dotcomexecAuthor Commented:
Good idea but that of course requires two dictionaries... Anybody have any idea where I could get such dictionaries?
TeRReFCommented:
Not really, the online dictionaries are DB driven. Why don't you take a massive .txt document and retrieve all the words from it? Will give you a good start to build you own dictionary. Something like:

<?php
// get file
$s = file_get_contents("YOUR_TEXTFILE");
print("blah");
// first lower case all text, then uppercase first letter of each word
$s = ucwords(strtolower($s));
// get rid of some junk
$s = str_replace(array("\"", "'", ".", ",", ";", ":", "!", "?", "\n"), " ", $s); //etc.
// make array of words
$s_array = explode(" ", $s);
$dictionary = array_unique($s_array);
// now write the array to file or to DB for use in application.
print_r($dictionary);
?>

The naughtywords array you have to make yourself I'm affraid (or google for it of course)
dotcomexecAuthor Commented:
It seems as if the dictionary is the big problem in this question.

So... if anybody can accomplish either of the two options I'll give them all the points:

Option 1) Find an extensive (no 100 word dictionaries!) dictionary which will never produce a bad (use your best judgment when it comes to 'bad' combinations) combination of 2 words

OR

Option 2) Find a 2 dictionaries. One which has all the words, and the second with a list of the inappropriate combinations.

I know there has to be something out there for this because all major online companies produce coupons this way; by combining two words together to make the coupon easier to remember.

*Admin, if this post should be moved please do so!

Thanks!
TeRReFCommented:
Thanks for nothing I guess...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.