Intro
.php
PHP code will be put in a file with extension .php. The most important php file is index.php which is also the page that the server searches when the site is accessed by users. When the user searches inside his browser for a specific website, the browser sends a request to the server where the site is stored, and more precisely to the index.php page of the site, which is the gateway to the site.
Usually index.php file is placed in the root folder of the website.
It is mandatory to insert opening php tag before coding. If html code is not followed by the php code then closing tag may be missing. Best practices tell us that at the end of the script we should put php closing tag:
<?php
// code
?>
Comments
The comments are very important for programmer. If we want to comment one single line we should use double slash (//) in front of the code or #sign.
<?php
// $number = 3;
# $number = 3;
?>
If there is a multilline code we should put it between /*
and */.
<?php
/*
I have a code on several lines
to help me remember later
what I wanted to code
*/
?>
Believe me even if you yourself create the code after six months you would hardly read it and understand it without helping of comments. The comments give you hints about the code you wrote. The comments are little notes wich help you very quicly what you wanted to code.
Semicolon
Every statement in PHP ends with semicolon:
<?php
$number = 3;
?>
Comments
Post a Comment