Home > DeveloperSection > Articles > Basic PHP Syntax

Basic PHP Syntax


PHP PHP 
Ratings:
0 Comment(s)
 2516  View(s)
Rate this:

Basic PHP Syntax

PHP is a server side scripting language which is executed on server and result sent in plain html format to client browser.

A PHP scripting block always starts with <?php  and ends with ?>. A PHP scripting block can be placed anywhere in the document. You can use shorthand tag <? (As starting tag) and ?> (as ending tag) rather than <?php  (as starting tag) and ?> (as ending tag), but for more compatibility you should have to use first one.

Syntax:

<? php ..... Scripting code to be executed.....?>

Example:

<html>

  <head>

        <title>First Php Script</title>

  </head>

 <body>

       <%-- Basic Php script syntax--%>

        <?php

               <%--Some php scripting code here. --%>

        ?>

 </body>

</html>

 

A PHP file contains html tag, just like html file, and contains some scripting code.

Here we have an example for displaying message with php script.

<html>

  <head>

        <title>First Php Script</title>

  </head>

 <body>

        <?php

               echo "Hello first PHP Script";

        ?>

 </body>

</html>

 

Now type http://localhost:85/MySiteFile/ in URL web address of web browser.

Basic PHP Syntax

Comments in PHP:

We use ‘//’ (double forward slash) to make single-line comment and ‘/* */ ‘for multi-line comment.

<html>

  <head>

        <title>First Php Script</title>

  </head>

 <body>

        <?php

               // Starting PHP comment

               /* Multi line

     Comment */                         

              echo "Hello first PHP Script";

        ?>

 </body>

</html>


Don't want to miss updates? Please click the below button!

Follow MindStick