Where you can learn to Be Your Own Geek!
Your first php program
Ok lets have some fun, fire up your wampserver. Once you've started that
up, you should have a little half moon shaped icon in the bottom right hand of your screen
looking like this:
Now if you left click that icon, you should get a menu looking like this:
This folder should be empty apart from a single file called "index.php file", leave
that one alone. Right click in the white space of the open folder and choose the option
Now if you've followed my html tutorials, you will remember our discussion about a root directory(review it here if you need to). For the sake of these tutorials, the folder "my_first porgram" that you just created is going to act as your root directory and you will be able to see the results of your work via that localhost page.
At the moment there's nothing in that folder, so lets get to it and make a php file to put in there, open up your editor. Most programming tutorials, php or otherwise do a stupid first program which does nothing more than print out "hello world" on the screen. While this does give you an example a very common function used in programming it's not very exciting, and there's only so many tutorials you can follow that show you the words "hello world" before you lose the plot and go psycho.
So lets do something a bit more fun, in your editor, type the code below, don't worry too much if looks a little confusing and daunting at first, we'll break it up later and go through each bit step by step:
echo "The ";
echo $first_mood." ";
echo $what." ";
echo $middle." ";
Now save this file in your C:\wamp\www\my_first_program folder as "happy_sad_what.php". Now go to that localhost page in wamp, click on your folder and click on your happy_sad_what.php file. You should get something like this.
Don't be alarmed if it isn't exaclty the same as mine. Try refreshing the page a few times and see what happens.
Ok when you've finished saying WTF!!! and calling me a stark raving lunatic, ask yourself if that wasn't more fun than this.
When you're finished messing around with the emotions of those poor monkeys, clowns, dogs and mice, move on to the next lesson here where we'll break down that code and make some sense out of what's going on there.
Lesson added Friday 1st May 2009
things to do list:
© 2008-2009 BYOGeek.com / nesperion.net