I’m creating a humble web browser-game in PHP. I’m making a “robbery” section…
I want to greet the user if he succeeds at a robbery. Some messages like “You’re the man!”, “A piece of cake, it was” etc.
I want more than, like, 5 different messages/notifications like this. How could I do this? how could I pick them from a .txt file, or have them imported from another PHP page which has these messages stored in variables to the “robbery” page…
Please, if you can provide a useful snippet of code, like a function for picking random messages, etc, that would be great.
Also if you can use OOP… 🙂
Thank you very much in advance…
Put your messages into a file, one message per line, and then you can load that file into an array using
file. TheFILE_IGNORE_NEW_LINESflag will strip the newline from the end of each element in the returned array. Then you canshufflethe array to randomize it.