How to use comments in PHP

admin_img Posted By Bajarangi soft , Posted On 03-10-2022

A PHP script is executed on the server, and the plain HTML result is sent back to the browser.

How Do I Use Comments In PHP

  • Default PHP syntax strat with "<? php" and ends with "?>".
  • You can placed your PHP script  anywhere in the document.

Syntax:

<?php
      // Here you write code.
?>
  • Aftre use of PHP syntax you have to use ".php" extention of your files.
  • it will contains HTML tags, and some PHP scripting code.
  • Below, we have an example of a simple PHP file that will return a string.

Example:

<!DOCTYPE html>
<html>
<body>

<h1>My BLogs</h1>
<?
echo "Welcome To My Blog Page !";
?>

</body>
</html>
 

Output:

  • it will return a string which we were passed in a 'echo' function.
//Output will look like this....

Welcome To My Blog Page !
 

Commenting PHP Code:

comment is the part of a program that exists only for the human reader and stripped out before displaying the programs result. There are two commenting types in PHP −

Single-line comments : 

 it is generally used for some short explaination or related note about local code in your PHP file.​​​​​

 Example:

<?
// Blogs started from here !! 
echo "Welcome To My Blog Page !";
?>

 

Multi-lines comments : 

They are generally used to provide detailed explanations when necessary or commenting some PHP code.

 Example:

<?
//Multi-line comment Example
// Blogs started from here !! 
// echo" Welcome to Blogs";
echo "Welcome To My Blog Page !";
?>

For both example output will be same,

Output:

//Output will look like this....

Welcome To My Blog Page !

Note:

 in a PHP if any expression that is followed by a semicolon (;) that is valid PHP statements that is enclosed by the PHP tags is a valid PHP program.

Related Post