PHP Comments , White Spaces and Case Sensitivity

By | 2018-03-08T11:05:34+00:00 November 1st, 2016|Categories: PHP|Tags: , , |0 Comments

This tutorials tells you, how to use PHP comments in your php code. This part of PHP lets the developer write human-readable lines. It is an optional but essential part.

PHP Comments :

PHP Comments help the developer to explain steps and way of reasoning throughout the program, it enabling the easier maintenance.

PHP comments Single Line:


# This is one way to put it
// Hide all your lines here and no user one will see.
echo "This is the only visible text in this code";

The output is as follow

This is the only visible text in this code

PHP multi Comments line :


/* A multiline Comment lets you add the following
features and information.
Author : Developer name
Objective: How to add Multiline
language: PHP
print "Only this phrase is visible";

Only this phrase is visible

If you are familiar with the C programming language, you must have come across this style of commenting. It provides algorithms and pseudocode used in finding solutions.

PHP Whitespaces :

The rules of PHP are lenient on whitespaces. This feature is significant in web design in achieving minimalism on the front end. It is also vital as far as coding is concerned.

It includes things like spaces, carriage returns, tabs, and others which leave blanks. PHP is insensitive to spaces; whether you leave one or ten or a thousand steps, the parser ignores them. For instance, find the fault in the code below:

echo "Here is how to calculate in PHP";?></br>
$lions =
= 20;

$animals = $lions      +             $zebras;
echo "The number of animals is ",

$animals,", there are 21 lions and 20 zebras";?>

The output is as follows

Here is how to calculate in PHP
The number of animals is 41 , there are 21 lions and 20 zebras

Notice the many spaces. Did you find the mistakes? Well compare that with the following piece of code.

<?php echo "Here is how to calculate in PHP";?></br>
<?php $lions=21;$zebras=20;$animals=$lions+$zebras;echo "The number of animals is ",
$animals," , there are 21 lions and 20 zebras";

The two sets of code are similar and give the following output.

Here is how to calculate in PHP
The number of animals is 41 , there are 21 lions and 20 zebras

There is nothing wrong with any of the code sets above. However, appropriate usage of whitespaces is for enhancement of readability.

PHP Case Sensitivity :

PHP is case sensitive. This is the part of rules of PHP that describes the definition of variables.
In the following code, the use of the same word for a variable but different cases will be interpreted by the parser as different words.

echo "Lions are $Lions, lIons are $lIons, liOns are $liOns, lioNs are $lioNs, and lionS are $lionS";


The output is as follows:

Lions are 21, lIons are 22, liOns are 23, lioNs are 24, and lionS are 24

PHP is a really powerful language that can be used to create dynamic systems. As we saw earlier, big companies have adopted it and used it to great lengths. You can learn the trade too, only of you follow the rules of PHP carefully and practice often.

Happy Learning 🙂

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment