Click to See Complete Forum and Search --> : Quotes generator in PHP, but...HOW?
kozumo
08-01-2001, 09:01 AM
I want to make a quotes generator in PHP that'll display a random quote everytime my index.php is refreshed.
Here's what I have in mind.
Firstly, I have quotes stored in a text file that is on the server:
blah1
blah2
blah3
I want to be able to read each line (a quote) and store it into an array. Then with a for loop, spit out a random quote whenever the page is refreshed.
I also have to be able to cat a quote to the text file without having to change the code part.
Fairly simple, but how? Any ideas?
Salmon
08-01-2001, 10:15 AM
Are you dead set on a reading the quotes from a file? A database would make the whole process (including management) *a lot* easier.
nanode
08-01-2001, 03:07 PM
I have numerous examples of code doing exactly this - all using mysql.
http://yunt.net/jokes/work.php
http://yunt.net/jokes/work.phps
The table looks like this:
mysql> describe hate_work;
+--------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| string | varchar(255) | YES | | NULL | |
+--------+--------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
and the data like this:
mysql> select * from hate_work;
+----+------------------------------------------------------------------------------------+
| id | string |
+----+------------------------------------------------------------------------------------+
| 1 | I can see your point, but I still think you're full of ****. |
| 2 | I don't know what your problem is, but I'll bet it's hard to pronounce. |
| 3 | How about never? Is never good for you? |
| 4 | I see you've set aside this special time to humiliate yourself in public. |
| 5 | I bet you're really easy to get along with once people learn to worship you. |
| 6 | I'll try being nicer if you'll try being smarter. |
| 7 | I'm out of my mind, but feel free to leave a message. |
| 8 | I don't work here. I'm a consultant. |
| 9 | It sounds like English, but I can't understand a word you're saying. |
| 10 | Ahhh...I see the ****-up fairy has visited us again... |
| 11 | I like you. You remind me of when I was young and stupid. |
| 12 | You are validating my inherent mistrust of strangers. |
| 13 | I have plenty of talent and vision, I just don't give a ****. |
| 14 | Visualizing? I'm already visualizing the duct tape over your mouth. |
| 15 | I will always cherish the initial misconceptions I had about you being competent. |
| 16 | Thank you. We're all refreshed and challenged by your unique point of view. |
| 17 | The fact that no one understands you doesn't mean you're an artist. |
| 18 | Any connection between your reality and mine is purely coincidental. |
| 19 | What am I?... Flypaper for freaks! |
| 20 | I'm not being rude. You're just insignificant. |
| 21 | And your cry-baby whiny-*** opinion would be...? |
| 22 | Do I look like a people person? |
| 23 | I started out with nothing & still have most of it left. |
| 24 | Sarcasm is just one more service we offer. |
| 25 | If I throw a stick, will you leave? |
| 26 | Errors have been made. Others will be blamed. |
| 27 | Whatever kind of look you were going for, you missed. |
| 28 | I'm trying to imagine you with a personality. |
| 29 | A cubicle is just a padded cell without a door. |
| 30 | Can I trade this job for what's behind door #1? |
| 31 | Too many freaks, not enough circuses. |
| 32 | Nice perfume, must you marinate in it? |
| 33 | CHAOS, PANIC, & DISORDER - my work here is done. |
| 34 | How do I set a laser printer to stun? |
| 35 | I thought I wanted a career, turns out I just wanted paychecks. |
+----+------------------------------------------------------------------------------------+
35 rows in set (0.01 sec)
Enjoy...