Ow! That makes my brain hurt. How can the P in PHP stand for PHP? Doesn't that create some infinite name like PHP: Hypertext Preprocessor PHP...bah you get the point. Its like that boxer George Foreman; you know the guy has been hit in the head too many times because all five of his children have the same exact name as him. I mean, even the things he invents have the same name. Don't think that's crazy? Call his house and ask to speak to George Foreman. See how long it takes to figure out the right one.
Before we begin, I am going to assume several things:
If you mentioned no to any of those (except the modicum one; you can skip that), then avert your beady eyes from my tutorial and go rectify the situation. If you answered yes to all of those, then come on in. Grab yourself a warm mug of hot cocoa and let us discuss the legacy of the first programming language created by a Yeti.
When programming blocks of PHP, you must always start with <?php and end with ?>. This tells the interpreter that the line of code you have written is PHP. Remember when you right PHP, you will usually be intermingling it with HTML.
Most tutorials start you off with that dumb "Hello World" script. Forget that. We are l33t PHP h4xors now. We don't want the world to know we exist. We are like ninjas. Or like that song from the Patrick Swayze movie: Like the Wind.
Does that guy ever wear a shirt by the way? [Does he need to? --Ed.]
<?php // This tells the browser you are using PHP
echo "Shhhh...don't tell the world we are here h4xoring their bases";
?> // This ends your PHP block of code
The above would print the following to your monitor:
Shhhh...don't tell the world we are here h4xoring their bases
In the above code, the echo command tells the computer to print what follows it to the monitor. You can also use the print command.
You will also notice the semicolon (;). This is a separator, placed at the end of a statement, that tells the program that this line is finished. Basically, it keeps your instructions separate.
You might have wondered about the // in the above example. This is called commenting. When PHP sees the // it skips everything on that line after it. You use comments to leave notes to future programmers (or even yourself) about what this line or block of code was used for.
If you want to do a whole block of comments, you can do this:
/* I have a bunch of comments to make and am too lazy to
use those stupid // symbols
Blah blah blah
Anything between the /* and */ is ignored by the program.
blog comments powered by Disqus