Page 1 of 1

Random Sentences - Question

Posted: Tue May 18, 2010 10:36 am
by peterhere
Can somebody post a little php snippet for this?

I have a textfile like this:

I {love|like|need} {coffee|tea}.
He is {cool|nice|awesome} {.|..|!}
Are you {hungry|tired|angry}?

The little php snippet should select one line of the textfile at random and create a random sentence from it, every time i start the php-script.

Example:

After starting the script, it selects line 1: "I {love|like|need} {coffee|tea}."
Then it creates a random sentence like "I like tea." or "I love coffee." (or something like this) from it.

Re: Random Sentences - Question

Posted: Tue May 18, 2010 10:40 am
by AbraCadaver
What have you tried that's not working?

Re: Random Sentences - Question

Posted: Tue May 18, 2010 10:54 am
by peterhere
I don't know where to start. My php knowledge is not big enough right now. But from such a snippet i could learn more.

Re: Random Sentences - Question

Posted: Tue May 18, 2010 11:42 am
by AbraCadaver
peterhere wrote:I don't know where to start. My php knowledge is not big enough right now. But from such a snippet i could learn more.
I would start with file() and shuffle(), then preg_match() and explode().

Re: Random Sentences - Question

Posted: Tue May 18, 2010 12:12 pm
by peterhere
ok thx!