I could bore you with indepth details about how it runs, what versioning system it uses etc, but I don't want to bore you
So I will sum it up by saying that PHP is one of the most popular and reliable server side programming languages in existance and that it has been proven by the sheer number of large programs written in it. (ie. vBulletin, phpBB etc)
Most Webhosting Companies, including Diagemshosting, Canaca, iPowerweb and the many other millions use PHP, so don't worry if you want to run a PHP-driven website. It's pretty easy to find a host to suit your needs. I'm getting off topic here, so if you are looking for a good webhost, I recommend searching at http://www.webhostingtalk.com.
You must always call a page written in PHP, *.php. Where * is a short description of what the file does, or anything that you understand. Say you were making a Quiz program, you could call your main file quiz.php.
PHP can be as basic or as complicated as you want it to be, with an infinite range of different functions, many included (others you can make yourself) and it's versatility there is next to nothing you can't do with PHP.
The most basic of these functions, is 'echo'.
Every php page, begins with:
Code: Select all
<?php
Code: Select all
<?
Code: Select all
?>
Code: Select all
/*
* To do, or not to do, that is the question
*/
Code: Select all
//
// Escape any quotes in the site description for proper display in the text
// box on the admin page
//
Code: Select all
// I'm hungry
Now you should have something that looks like:
Code: Select all
<?php
// I'm hungry
?>
Common types of comments are the double slashed type (//) and the asterisk type (/*)
The asterisk type must be opened and closed:
Code: Select all
/*
Code: Select all
*/
The double slashed type is the simplest, you simply type two slashes, and add your comment. Done. They do not need to be 'closed' in a sense, like the asterisk type do.
We touched on 'echo' a little earlier. With echo, you can print anything you want. Not print as in, print a page through your printer, I mean print on to your browser screen!
With simple code like:
Code: Select all
echo 'Hello World!';
No 'echo' or the apostraphe or semicolon. That is because they are required for it to work. All lines of code must end in a semicolon, that is a given. However, with the apostraphe, this can be tweaked. These are used so PHP will know what exactly to display. You can use inverted commas too (" ") but the apostraphe is more secure when it comes to Database queries and advanced code.Hello World!
So our file now looks like:
Code: Select all
<?php
// I'm hungry
echo 'Hello World!';
?>
Code: Select all
echo 'I want food';
Code: Select all
<?php
// I'm hungry
echo 'Hello World!';
echo 'I want food';
echo 'I might buy some Nachos.';
?>
The code above displays the following in your browser:
Too messy, so you can use HTML in your code. You can use any code you want, I will explain in the next lesson, at the moment all you need to know is <br> (linebreak, or paragraph).Hello World!I want foodI might buy some Nachos.
By putting <br> in your code it will skip a line between your text to be echoed. Confused? Here's how:
Code: Select all
<?php
// I'm hungry
echo 'Hello World!';
echo "<br>";
echo 'I want food';
echo "<br>";
echo 'I might buy some Nachos.';
?>
Play around with it, add more lines of <br>, remember the semicolon and apostraphe rules still apply when using HTML.Hello World!
I want food
I might buy some Nachos.
Note: If you are using HTML, you must use inverted comma's around the <br> ("<br>") or else PHP may display the HTML code. This is to distinguish between what you want displayed, and what you want to be run in the background. If the text is enclosed by apostraphes, PHP thinks you want that to be displayed in the browser, not to be run. This applies for PHP variables, HTML and other code you may wish to run.
To finish, our file looks like:
Code: Select all
<?php
// I'm hungry
echo 'Hello World!';
echo "<br>";
echo 'I want food';
echo "<br>";
echo 'I might buy some Nachos.';
?>
Good luck, play around with the code, replace the text and the comments, and if you are comfortable, the HTML code. Attach the files in a PM or Email to me if you want to see what it looks like live on the internet.