Random Sentences - Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
peterhere
Forum Newbie
Posts: 3
Joined: Tue May 18, 2010 10:32 am

Random Sentences - Question

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Random Sentences - Question

Post by AbraCadaver »

What have you tried that's not working?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
peterhere
Forum Newbie
Posts: 3
Joined: Tue May 18, 2010 10:32 am

Re: Random Sentences - Question

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Random Sentences - Question

Post 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().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
peterhere
Forum Newbie
Posts: 3
Joined: Tue May 18, 2010 10:32 am

Re: Random Sentences - Question

Post by peterhere »

ok thx!
Post Reply