articles

Home / DeveloperSection / Articles / Basic PHP Syntax

Basic PHP Syntax

Basic PHP Syntax

Anonymous User 5040 02-Sep-2011

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 html 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>



php php 
Updated 04-Mar-2020
I am a content writter !

Leave Comment

Comments

Liked By