PHP Syntax

php syntax. PHP Script always starts with  <?php  and  end with  ?>

<?php
// PHP code here
?>

You can write php script in html document I have no rule for it nowadays server which gives you shorthand support You will also write  <?php  And  ?>  Even then your php script will be considered correct, but due to the different ways of server and browser excess and support, it will be appropriate that you write  <?php  and  ?>

An example given below which gives the output as “Hi, This is PHP Syntax Example”.

<!DOCTYPE html> <html> <head>   <title>PHP Program</title> </head> <body> <?php  echo "Hii, This is PHP Syntax Example";  ?> </body> </html> 

PHP Syntax Explanation

  • Any PHP Script starts with  <?php  and ends with PHP Script  ?>. This means that whatever we write the code of PHP, we write in the same two symbols  <?php ?>  Outside if we write a PHP script, it will not be valid.
  • The second thing to note in PHP is that the number of php pages we create will be save with .php extension, if we do not save them with the .php extension then the code written in the page will not be able to run.
  • Another important thing about PHP is that the way we can see HTML’s source code on our Web browser, you can not see PHP’s source code on your Web browser because PHP is Server Side Scripting Language And the PHP code is execute on the server, so its source code is not visible on our browser.
  • If you want to write some words or sentences in PHP on Web Page, then you will have to use echo. echo is a reserved keyword used to show a word or sentence on a Web page.
  • It is not necessary that you write php code inside the  <body> </body>  you can write PHP code in any part of the entire page. All you have to do is remember that whenever you add a PHP code to a page then save that page with the .php extension.

PHP Comments

Like any other language, you can also comment on the PHP code. Comments are not parse by parser. Comments Any code written to explain. Any other programmer can understand that code by writing comments.

Writing comments is considere a very good practice. After years, even if a programmer looks at your code, then he can understand it very well.

PHP code can be commente differently. It is being told about it.

Single Line Comment

Single line comment syntax is use when the text to be comment is less than one line. Example of single line comment is give below.

// your comment here

Apart from this you can also define the single line comment in the way given below.

# your comment here

Multi Line Comment

Multiline comment syntax is used when text written in the form of comment is greater than a line. An example of multiline comment is being given below.

/* This is Multi Line Comment
   This is second line
   This is third line
*/