Introductory PHP For Non-Programmers
When you started reading this sentence you assumed lo acabarÃa en inglés. However, I didn't finish in English. This begs the question, 'In which language did I finish?' Unless I tell you the language, you'd have to run around and compare the words against known words in order to learn that it was Spanish, but I'd bet you'd give up and move on first. Servers work much the same way; if you don't let it know the language it assumes you're speaking to someone else (the browser) and sends it along. Servers aren't even friendly enough to give it a whack and see how it comes out.
So, what's server-speak for "Here comes PHP!"? Well, it definitely looks foreign:
Sure. Whatever. It's no use telling the server you're speaking PHP because you only know how to say "I speak PHP". What's that going to do for you? Well, imagine you were visiting a scripts site and wondering how you could put today's date on your webpage when you come across the following little snippet:
To display the date on your webpage, find the area you want to put the date then insert the code below.
echo date('m/d/Y');
Now, you're equipped with 2 statements: "I'm going to be speaking PHP" and "Today's date is mm/dd/YYYY". You then edit the file you want to put the date in by inserting this code in the desired location:Put the file back on the server and you're date shows up exactly as the snippet said it would. Or does it?
If you got lucky, it showed up. If not, there's a little more to learn. There's actually more than one way to tell the server that PHP is coming and I've only covered one way - the other ways aren't necessary for you to know in order to use PHP on your site. Most servers require a bit more information first - they want the name of the file to say whether PHP is there or not. To tell the server that PHP is inside the file, you need to change the extension (the part after the dot) to php. Uh, sure, the extension. Does this guy speak English? YEP! lol. If that wasn't clear, let's illustrate by assuming your file was called index.html when you downloaded it to edit. Before you upload that file back to the server, you need to change "html" to "php", so that the file is called index.php. Without that change most servers won't even look for PHP. The nice thing is that even if a file ends in "php", the server still looks for those opening pieces saying "Here comes PHP!" before trying to read what follows in PHP and just sends everything back to the browser which is outside of PHP, so you don't hurt anything!
Tired of reading? Me too! And, we can only do a couple of things! Or can we? There are a lot of scripts out there which require you to copy and paste a little code here and there or to include a file. In those cases, you are now leaps and bounds ahead in getting them to work!
Jeremy Miller - Webmaster of Script Reference - The *NEW* PHP Reference & Tutorial Site For Non-Programmers