Basic Syntax

Posted on Updated on

Basic PHP Syntax

A PHP script may be placed anyplace within the document.

A PHP script starts with < ?php and ends with ? > :

< ?php

/ / PHP code goes here

? >

The default file extension for PHP files is “.php”.

A PHP file ordinarily contains markup language tags, and a few PHP scripting code.

Below, we ‘ ve got AN example of a straightforward PHP file, with a PHP script that uses a intrinsicPHP perform “echo” to output the text “Hello World!” on an internet page:

Example

< !DOCTYPE html >

< html >

< body >

 < h1 > My 1st PHP page < / h1 >

< ?php

echo “Hello World!”;

? >

< / body >

< / html >

Note: PHP statements finish with a punctuation (;).

Comments in PHP

A comment in PHP code may be a line that ‘ s not read / executed as a part of the program. Its solelypurpose is to be browse by somebody World Health Organization is staring at the code.

Comments may be used to:

• Let others perceive what you ‘ re doing

• Remind yourself of what you probably did – Most programmers have seasoned coming to their own work a year or 2 later and having to re-figure out what they did. Comments will cue you of what you were thinking after you wrote the code.

PHP supports many ways in which of commenting:

Example

< !DOCTYPE html >

< html >

< body >

< ?php

/ /  this is often a single-line comment

 # this is often conjointly a single-line comment

/ *

This is a multiple-lines comment block

that spans over multiple

lines

* /

/ /  you ‘ ll be able to conjointly use comments to go away out elements of a code line

$ x = 5  / * + 15 * / + 5;

echo $ x;

? >

< / body >

< / html >

________________________________________

PHP Case Sensitivity

In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functionsaren ‘ t case-

sensitive.

In the example below, all 3 echo statements below square measure legal (and equal):

Example

< !DOCTYPE html >

< html >

< body >

< ?php

ECHO “Hello World! < br > “;

echo “Hello World! < br > “;

EcHo “Hello World! < br > “;

? >

< / body >

< / html >

However; all variable names square measure case-sensitive.

In the example below, solely the primary statement can show the worth of the $ color variable (this isas a result of $ color, $ COLOR, and $ coLOR square measure treated as 3 completely differentvariables):

< !DOCTYPE html >

< html >

< body >

< ?php

$ color = “red”;

echo “My automobile is ” . $ color . ” < br > “;

echo “My home is ” . $ COLOR . ” < br > “;

echo “My boat is ” . $ coLOR . ” < br > “;

? >

< / body >

< / html >

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666

Email:info@technocampus.co.in

**************************************************************************************************************

Please fill the FORM and we shall contact you soon.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s