3. PHP – Constants and Comments

Posted: September 20, 2013 in Hypertext Preprocessor (PHP)
Tags: , ,

Constants :

Constants as the name indicates, as they are defined they cannot be changed during the script. A constant is an identifier. A valid constant starts with a letter of underscore, and are automatically global across the script. To set a constant, we use the function, define(). For an instance :

<?php
//Constants
define (“constnt”,”This is a constant and cannot be changed”);
echo constnt;
?>

Comments :

PHP supports three different types of comments.

  • Multi-line comment as in C.
    /*——–comment——–*/
  • Single-line comment (//) as in C and C++.
    //———comment———-
  • Single-line comment (#) as in Perl.
    #———comment———–

Here is the code to demonstrate the above :


<!DOCTYPE html>
<html>
<body>

<?php
//Constants
define ("constnt","This is a constant and cannot be changed");
echo constnt;

//Comments...

/*php
supports
multi-line
comment.
*/

//single-line comment.

#And also the single-line comment using #, as in perl.
?>

</body>
</html>

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