PHP is great. It is so flexible, understandible and accepted throughout the world wide web. At south coast web we write alot of designs using PHP just for these reasons. My tutorials will involve alot of PHP as it is my favourite scripting language. firstly however we need to learn the basics. if you wish to read a complete tutorial that lists most commands please visit w3schools website and click the PHP links. I will try to help with a few simple tutorials that should get you along the way.
To start every webpage you write must end with the .php tag. this makes the server realise that there is PHP within the page. The page is written as a normal HTML layout but with the acceptance of PHP scripts within.
To change to PHP mode you need to use:-
<?php
// this tells the server to start php
// this is a single line comment
/* This Is A
Multiline comment */
// this tells the server to stop php
?>
As
you can see i included a few items to give you comments within pHP as well as the opening an closing tags for pHP.
the most frequently used PHP command has to be echo. this can be used to input data into html as well as display text onto screen.
<?php
echo "Hello Everyone" ;
?>
this will quite simply give you the line : Hello everyone.
You can include html within a PHP statement
<?php
echo "<br/>Hello Everyone<br/>This is a line down<br/>" ;
?>
This will give you :
Hello Everyone
This is a line down
When using an echo statement you can use either the single quotes or double quotes. Double quotes proccess everything within the quotes. Single quotes will not get proccessed as php code. so if you qant to echo a variable within a html line you can use 2 methods :-
<?php
$name = ‘Kenny Turner’ ;
echo "The person writing this is $name . Please Enjoy" ;
echo ‘The person writing this is’.$name.’Please Enjoy’ ;
?>
Both will output the same. However the second statement will proccess quicker as it already knows which part of the statement contains the PHP.
When using the single quotes you must use the . to join sentences together.
Just As a quick note, every PHP line must end with a ; Failure to do this will result in a page display error. When you first start PHP ing this will happen on a lot of occasions and you will spend alot of time correcting the problem.
I hope this tutorial has given you the basic introduction into PHP.
