Comments in html and php. Comments in HTML, CSS, PHP

25.04.2017


Hello everyone!
Continuing to learn PHP fundamentals from scratch!
In this tutorial I will tell you what a comment is in PHP and in practice we will try to write our comment in the code. But that is not all. I also want to tell you how to comment out the code and why it should be done at all.

What is a comment inPHP
Comment inPHP- this is a php developer's hint for quick navigation in the code, as well as for edits.

The comment in PHP is not visible to the user who opened the web page for viewing. Even if the user decides to look at the source code of the page, the comment will still not be visible, since all php.

PHP code comment

There are 2 kinds of comments for PHP code:

→ one line
→ multiline

⇒ Single line comment for PHP
For a one-line comment, use the symbols "//" or "#"

After these characters, everything written on one line will be ignored and considered as a comment.

Subscribe to update "; # subscription (this is a comment)?>


Subscribe to update

⇒ Multi-line comment for PHP
A multi-line comment for PHP starts with a "/ *" and ends with a "* /".
Anything between these characters will be ignored and treated as a comment.
A multi-line comment is used if there are multiple lines in the record.

On the screen, you will only see the following text:

Hello blog readers - site !!!

P.S .: Always comment out your code. If you think that you will remember everything you did in the code in 1-2 years, you are mistaken, the chance is very small. Even if you remember, you will have to spend a lot of time studying what, where and why ...
Do something pleasant for yourself in the future - comment out the code and then you will say to yourself "THANKS !!!".
Leave a comment in the code, it will take 1 minute of time, but it will save you a whole day in the future.

Comment out PHP code

Let's say you wrote php code, but for some reason you need to remove 2 lines from the code.
I am in no hurry to remove something from the code, especially if it is php code, I would rather comment it out. What if you need to return the code. It is easier to uncomment than to write the code in a new way.

How to comment out the code inPHP
Example with one line comment:

Subscribe to the update ";?>

An example with a multi-line comment.

From the author: commenting is one of those features that is easy to implement. At the same time, these editing elements can be of great benefit to developers who are handing over their code. Today you will learn how to comment out a block in PhpStorm. We will also consider the rest of the development environment functionality for commenting the contents of the program.

Comments: good and bad

Code commenting is available in most programming languages ​​(possibly all, but with varying degrees of availability). Typically, verbal explanations are used to help other team members develop further, or simply to remind ourselves that this area needs fixes (“FIX ME”).

Of course, an explanation of what is written is a blessing. But with the help of comments, you can also cross out all the good aspects of the code. To prevent this from happening, it is necessary to distinguish between the types of comments:

documenting. A good association would be the concept of documentation for various software. Such comments help you to use the code like an instruction. Such commenting is not perceived as superfluous, because without it there is nothing. Imagine that someone has used an authoring framework and does not tell you how to use the program;

JavaScript. Fast start

explaining. Good code usually doesn't need them. The more lines of comments you see in a program, the more likely it is that the program is poorly written. Of course, this is not an absolute rule.

Explanatory comments can be useful for those who will fix the code in the future. For example, many young professionals see a field for improvement everywhere. They believe that things were worse before them, and now is the time to fix every single feature.

Sometimes a similar feeling overwhelms the professionals. For example, when everything looks surprisingly crooked, there must be a better solution. To save followers from looking for the best, the programmer can leave a note like this: # time_spent_here = 24h

After such words, few people want to spend so much time. Thus, you are warning that many different options have already been sorted out. At the same time, you should avoid such attacks: #i_hate_this, # try_to_do_better_ass %% le. In this way, you are only showing an unprofessional attitude. Don't compromise yourself and your employer.

But documentary commenting of the code can become a ballast for the programmer. As a rule, these are massive sections that distract directly from programming. But to display the code without comments, the main IDEs have a corresponding function. PhpStorm should be no exception, but alas. Look for the feature in the update docs.

Tag as a functional element

While commenting is intended to be an explanation and aid for team development, these features are not used as often. As a rule, tags are placed where they want to stop the execution of the code. Let's say you have PHP embedded in HTML. And you don't want to erase it, you just want to see what the page looks like without it. To do this, you must follow the following syntax:

JavaScript

...
...

…< div > . . . < / div >

< ? -- закомментированныйкоднаphp -- >

< div > . . . < / div >

As you can see, with simple actions, you can stop the execution of the code without even performing any complex operations. But, in fact, this is not the height of optimization yet. Additional convenience for the developer is provided by the phpStorm IDE itself. Using highlighting and keyboard shortcuts, you can comment out the selected segment of code without attaching specialized tags. This can be done as follows.

Using a method convenient for you, select a fragment of text (mouse, shortcuts).

Press the keyboard shortcut Ctr + Shift + /

In addition, you can comment on the current line. Everything is the same, only without Shift.

The advantage of this type of commenting is the simultaneous coverage of several languages. PHP is rarely on its own. This way, you don't have to resort to tagging each one. The environment supports several more web languages. Just select a fragment and sell the combination - this is the multilingual code and commented out. In the same way, it can be made active.

That's all for us. If you have not used these features before, we advise you to get started. Abbreviations make work faster and better.

JavaScript. Fast start

Learn JavaScript basics with a hands-on example of building a web application

Comments in PHP are similar to comments used in HTML. In PHP syntax, comments always begin with a special sequence of characters and all text that appears between these special characters will be ignored by the interpreter.

In HTML, the main purpose of a comment is to serve as a note to developers who can view your site's source code. PHP comments differ in that they will not be displayed to visitors. The only way to see PHP comments is to open the file for editing. This makes PHP comments useful only for PHP programmers.

In case you forgot or didn't know how comments are made in HTML, see the example below.

Php comment syntax: single line comment

While html has only one kind of comments, PHP has two whole types. The first type we'll discuss is the one-line comment. That is, a comment that tells the interpreter to ignore everything that happens on this line to the right of the comments. To use this comment, use the characters "//" or "#" and all text on the right will be ignored by the PHP interpreter.

Psst ... You can "t see my PHP comments!"; // echo "nothing"; // echo "My name is Humperdinkle!"; # echo "I don" t do anything either ";?>

Result:

Hello World! Psst ... You can "t see my PHP comments!

Note that several of our echo commands were not processed because we commented them out with comment special characters. This type of comment is often used to quickly write down complex and confusing code, or to temporarily remove a line of PHP code (for debugging).

Php comment syntax: multiline comment

Like HTML comments, PHP multi-line comments can be used to comment out large blocks of code or to write comments across multiple lines. Multi-line comments in PHP start with "/ *" and end with "* /". Anything in between these characters will be ignored.

Result.

... today in this short but useful article, we will figure out how different program code is commented on. I will not say much, because if you are interested in this, then you have already faced the questions of this problem, and you have an idea of ​​it.


You came to the address ... but a few words for clarity and the benefit of the case. You've probably seen how this is done with CSS code, since css is of most interest to many beginners, like me.

… Good!

But note that comments are also used in html and php... But most beginners get confused at the initial stage of their work with the site and do not know how to add the necessary explanations to themselves. After all, it happens so, for example, you need to deactivate for some time html code, and then again resume its function - it's easy to implement if you have made notes for yourself in the "margins", but you never know what.

But what should be remembered about "comments" in general - everything here is strictly dependent on which file you are working with specifically, and therefore the application code is different.

Commenting out the CSS code

a: hover, a: focus (color: # D5071E; text-decoration: Overline; / * UNDERLINE UP * /)

This is how you explain yourself to yourself. Or you can even comment out this css script altogether like this: just wrap

/ * CODE here * /

/ * a: hover, a: focus (color: # D5071E; text-decoration: underline; / * UNDERLINE * /) * /

I draw your attention to the fact that - you can comment out the full cycle of the css code in this way, but !! then you have to remove repeated comments / * UNDERLINE BOTTOM * /, or play with slashes, if the explanation is important))

Otherwise there will be an error !!

Note:

If you open the source code of the page - Ctrl + U and take a look ... we will see that the commented-out piece of css code is beautifully displayed in the generated document! this is if css was used (properties were set) directly in html

And, as you know, if you go from the source code by reference to the css document of your active template - all comments can be observed and studied)) if someone needs it. But this is unlikely)

English adverb (words) will be readable. Russian symbolism - no.

Commenting out the HTML code

The XML file is commented in the same way.

Important: always check the code provided in the articles, at least visually) otherwise there may be errors.

The usual carelessness in formatting can be time-consuming, for example, the COMMENTED code shown above is often erroneous: instead of two short hyphens, an em dash appears:

For your information:

as mentioned in the previous remark - so is the comment-out ... html code is displayed in the generated document!

Keep this in mind.

And here's another thing:

in addition to the fact that the commented code is displayed in the source code of the page (which means it is processed in a sense, although it will be invisible on the page too!) - it is better to remove some php functions in conjunction with html from the active document.

For example:

will be visible in the document and the functionit will work out its job wonderfully: that is, the information will not be seen in the frontend, but in the source - it will be clearly displayed! and this is a bespontovy request to the database: all this is a trifle, but you need to know!

It is possible to do this if you do not want to take out a piece of code from the document:

add before the necessary "extra" html code the opening... inline function ... and closing?> ...

In a word, this is how you can do it if the code is large:


**/ ?>

then the source will be clean!

Or more simply:

Let's comment out the function itself in the html document. The source code in these cases will be clean with respect to the development of functions!

how to comment out JavaScript

if (beingShown || shown) (// don "t trigger the animation again return;) else (// on the line apply ANY COMMENT // on the line apply ANY COMMENT // true;

For clarity, I grabbed this example JavaScript code in the net, slightly adjusting the punctuation. It doesn't matter ... The main thing is to understand the principle ...

As you understand the slash "//" is double, this is the SIGN of the comment ... ONE LINE!

The rest of the JS code is commented out like php, more on that below:

remark:

Commenting out the PHP code

... and ... here it is the same - slash-slash ... one-line.

But note that it can be annotated just like CSS-code.

... or so you can comment out - a one-line option, when we use NOT TWO SLASHES, but BECAR (hash) before the commented line:

... Naturally, you need to comment carefully in the code loop!

... or in the same way - similar to the above example for CSS ... i.e. this / * code * / commenting option will work for both CSS and JS codes!

But in this way, you can comment out a more voluminous explanation to the PHP code, somewhere between its main examples ...

You can also comment in php loops like this, if the code is mixed ... php and somehow html

Similar to above:

For example, some kind of function ... somewhere in the general code (or a loop in html):- you can comment out, that is, add your own label like this:

or so: a one-line option ...

Intelligence:

php code is not visible in any source codes !! only its functional result is visible - working off!

In general, that's all that I wanted to report today!

Now you can experiment ... Good luck.

And of course, read the articles of the site and subscribe:
I share my bitter experience - some knowledge, for your sweet well-being))

... the city of webmasters Mikhalika.ru© - Easily with WordPress