To write your php code, you need to wrap it inside PHP tags. You can think of php tags as a boundry line for php code on your page. Php tags are usually in a couple shape just like any html tags.
Php starting tag is <?php, while the ending tag is ?>
The standard way of writing php tags is
1 2 3 |
<?php //some PHP code here ?> |
Some php code can also be written inside a <script> tag:
1 2 3 |
<script language="php"> //some PHP code here </script> |
ASP style can also be used to write php code:
1 2 3 4 |
<% //some PHP code here %> |
A short way of writing php tags is:
1 2 3 |
<? //some PHP code here ?> |
In this php tutorial we will stick to standard way of writing php tags: <?php … ?>. This way we will be sure it will work on any server running the php interpreter.
In PHP we will be using different small element again and again, some of them are:
- semicolons (;) : to end lines
- normal brackets, or parenthesis ( ): most of the time represent a function.
- square brackets [ ]: are for arrays
- curly braces { }: define the block or body of a structure.
To read about PHP comments, click here.