Article content

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_Syntax

Code 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

<?php
... php code ...
?> 
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

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.

Discussion

Submit your comment

Text:

Your name:

Your email:

Show my mailaddress (spam protected)

Your website:

Show my website

Featured Article

PHP Variables and strings

A variable is a means of storing a value, such as a text string or a number. In PHP you do not have to declare your variable, as it's automatically declared when you set it. Since you do not need to declare the variable, you do not have to specify what kind of data it contains either.

Topics
Magicode's own open source project
From the forum / Latest comments
You may also want to to check out these links: sendanonmail.com, superstrongpassword.com.