PHP Magic 8-Ball
Thursday July 6, 2006
I admit it, once in awhile I waste time time on silly websites with card tricks, ghosts jumping out of pictures, and coin flips. You know the ones... they get passed around to you in emails... don't pretend you don't, we're on to you! In the spirit of these time burners, our new tutorial shows you how to make an online magic 8-ball using PHP.


This is more a question then comment, why did you use multiple IF statements instead of a switch loop? Wouldn’t the latter have been much easier and more compact?
– hagakure
Hello!
There was no programming reason why I did it that way over a switch loop
I tend to lean towards if/elseif anyway (no particular reason) and I hadn’t covered switch yet on the site (didn’t want to confuse people who are just learning by using a function we had not yet covered)
But alas, since you gave me this reminder I’ll be adding some info on switch () today
Oh…
Well that makes sense, I haven’t had the chance to read all of the articles or I would have known that…
Keep up the good work.
– hagakure
This is great. A “Magic 8-Ball” is one of the first programming feats I did in my first Web job. I did it as a joke, and it was a lot of fun to direct people there when they asked me questions.
Hello,
I believe this code is correctionful. I mean, it wastes alot of space, uses conditionals wrongly, etc.
______________________One problem, I am using the Zend Enviorment and it tells me that $question is undeclared.
Help please.
Thanks for the amusing script, which I adapted as a bit of Christmas silliness for friends. Some found it didn’t work, apparently because of the smart quotes in echo $_SERVER[’PHP_SELF’]; … changing these puts the intended text in the form’s action attribute, which otherwise is empty. Oddly enough, the buggy version worked for me and most of my visitors.