PHP Syntax

PHP Syntax

 

Basic Syntax of PHP

The set of rules, principles and processes that define the structure of statements in a computer language is called Syntax.

The set of rules or principles that define how a PHP program can be written called PHP Syntax.PHP (Hypertext Preprocessor) is a widely used open-source general purpose scripting language and it is a very flexible language.But there are a few rules that you need to learn about its syntax and structure which are followings:

learn PHP Syntax

1).Semicolons

Each PHP command is ended with a semicolon, like this:
$x += 10;

2).The $ symbol

In PHP,  you must place a $ in front of all variables. This is need to make
the PHP parser faster.

Example:
$Number = 1;
$string = “Hello”;
$array = array(“One”, “Two”, “Three”);

 

3).Variables

Variables are the names you give to computer memory locations that which are used to store values in a computer program.

In PHP all variables start with a $ sign.

Example

(String variables)
$username = “Fred Smith”;

 

(Numeric Variables)

$count = 17;

for storing the floating numbers, the syntax is  same

$count = 17.5;

(Arrays)

$Students = array(‘Arian’, ‘Theon’, ‘Grego’, ‘Chris’, ‘Anne’);

 

Main Syntax

The main syntax of PHP code:

<?php
// PHP code
?>

echo” is a built-in PHP function that is used to display the output text on a web page.

The scripts of php is begin with <?php and ends with ?>.

 

The syntax of a simple PHP file:

 

<!DOCTYPE html>
<html>
<body>

<h1> Heading </h1>

<?php
echo “PHP CODE”;
?>

</body>
</html>

 

Example:

A small PHP “HELLO WORD” example

<!DOCTYPE html>
<html>
<body>

<h1> My First PHP Example </h1>

<?php
echo “HELLO WORLD :)”;
?>

</body>
</html>

To learn more about PHP and PHP Comments Click Here.

Leave a Reply

Your email address will not be published.