PHP is a computer language for the world wide web. You may think want PHP
stands, but actually it does not stand for anything
unlike many other computer languages.
PHP Editors:
There are many php editors out on the market, some free, some paid. A very
popular editor is Dreamweaver, but you have to buy it first. I use
PHP Eclipse, which is a plugin for Eclipse, which is an Open Source software.
But for this tutorial all you will need is notepad.
How-To open a PHP document:
To open a php document or to start php all you have to type is:
<?php
Or:
<?
To close a PHP document is to type:
?>
In between these 2 tags you can then execute your PHP code.
Print text to the browser:
To print some text to the browser you have to do the following:
<?php echo 'Hello World'; //This will print 'Hello World' to the browser. ?>
Now the echo command is telling PHP to print the following text to the browser.
Notice how I have a ';' at the end
of the end. If you do not add this, then you will not be able to execute any
more PHP code or you will get an error.
This is telling php that this line of code is finished, and you then want to go
onto the next line of code in your document.
Saving a PHP Document:
When saving a php document, you want the extension to be '.php' eg:
'my_first_app.php'
You will then need a server that supports PHP to view your the document you
just created.
Comments:
Comments are so you can add a comment in your php document.
If you type '//' (without quotes) this will then comment anything you type on
the current line, like what i have done in the example above.
If you wish to comment more than 1 line, then you will have to type: '/*' to
open it, and '*/' to end the comment.
Example:
<?php /* Start the comment This is a multiline comment. More text. End the comment here */ echo 'Comment Finished'; //Comment that will only work on the current line. ?>
Variables:
Variables is something that will hold data for you. The later you can use the
variable later in your code.
Example:
<?php $var = 'This is a variable'; //Store 'This is a variable' in the varaible called: '$var' echo $var; //This will print what ever is stored in $var. ?>
If Else Statements:
If else statments are one of the most important features in PHP aswell as a lot
of languages. It allows for conditional execution of code.
Example:
<?php $num1 = '1'; //Store some data $num2 = '2'; //Store some more data if ($num1 == $num2) //Make sure you type '==', this will then check if $num1 = $num2. If you just put '=', Then $num1 will equal $num2 { //Start the code to execute echo 'Success'; } //End the code that you executes else //If $num1 does not equal $num2 then we want the execute the following code: { echo 'Failed'; } ?>
written by my good friend ben to go on my website, But I shut down on submitting tutorials when he gave it to me.