PHP Basics: Syntax


PHP’s language syntax is similar to that of most programming languages such a C, as PHP was primarily based of the C language. However with PHP you are not required to compile the code and the code you write must be contained within a tag that starts and ends the PHP code.

<?php // This begins the PHP block
// Your PHP code goes here
?> // and this closes the PHP block

As PHP code is used in conjunction with HTML this allows for easy transitions in and out of PHP.

Comments

There are two different types of comments, a single line comment and a block comment.

<?php
// This is a single line comment

/* this comment
can go across
multiple lines */
?>

Hello World!

The first step to learning any language is to print Hello World. In PHP this is very simple and done with one line of code.

<?php
echo “Hello World!”;
?>

echo is the basic command for printing text to a page.


Thank you for reading. PHPinformation.org, your home for quality PHP Information.

Hi, Stranger! Leave Your Comment...

You must be logged in to post a comment.

Powered by WP Robot