PHP basics tutorial
What is a syntax? Laically spoken, the syntax represent a group of rules that every code has to fulfill.
PHP code has to be inside of key words (tags):
<?php
/*.....here you put the code....*/
?>
or short
<?
/*.....here you put the code....*/
?>
Each code order, definition variable has to be ended with ";".
How to save PHP pages?
If you intend to put PHP code into your HTML pages and want the server or web browser to show your page right you have to use .php extension, instead of standard .html, for your pages. For example, instead of index.html it should be written index.php
Variables
It is used for temporary saving a certain values (a number, text...). The value, saved in variable, can be used many times after, through the whole code.
PHP variables are defined in this way: $variable_name = value;
The dollar sign ($) in front of the variable is a bound.
Note: variable names are case sensitive. For example, $name and $Name are two different variables.
The rules you have to follow while naming variables are:
- PHP variables have to begin with the s letter or "_" sign.
- Name can contain next signs a-z, A-Z, 0-9 or _.
- Variables with more than one word should be divided with _ like
$my_variable
- It can also be divided using upper and lower case letters like
$myVariable