PHP Syntax
PHP Tutorial for novices - The Syntax
Definition of syntax
Syntax - The rules governing the formation of statements in a programming language. The PHP syntax is similar to other programming languages, like C, Java or Perl, so if have some experience with other languages, you'll feel right at home in PHP. Permalink for this article http://mirror.magicode.org/content/PHP_SyntaxCode container
PHP code is contained within an opening and closing tag, like this:
<?php
... php code ...
?>
This text was originally written for http://blog.magicode.org
You may also use the shorthand variant, like this
But this is generally not recommended, since it requires shorthand support to be available on the server, and since this is not a default setting, it is not always available.
If you see this notice on any site other than magicode.org, it's probably been lifted without consent
<?php
... php code ...
?>
Inserting comments
There are two ways of inserting comments in PHP. One is adding two forward slashes, which comments out any text after the slashes until the end the line, and the other is to contain the comment within /* and */ to make a large comment block.Example:
<html>
<body>
<?php
//This is a comment
/*
This is a
comment block
*/
?>
</body>
</html>
The semicolon
The semicolon is special in PHP as it marks the end of a command and is typically used at the end of each sentence in PHP scripts that you download. Spaces are ignored, so the following command:
echo "Hello World";
is identical to this:
echo "Hello World" ;
The command echo will print the string in the brackets to the screen.
