The code of modern programming languages is quite convenient for human perception compared to machine codes, assembler, or the first high-level programming languages. Nevertheless, the constructions of the language are dictated by the architecture of the computer, and, creating programs, the developer, willy-nilly, uses computer logic, not human logic. This often leads to the creation of quite complex constructions that need explanation in ordinary language. Comments are used to insert such explanations into the code.
PHP provides several ways to insert comments, variants of which are presented in Table 3.1.
Table 3.1. PHP Comments
||C ++ style comment, starting with a double slash // character and ending with a line break|
||Commentary in the style of UNIX scripting languages, starting with the octothorpe/hash symbol # and ending with a line break|
||If the two previous comments are limited to only one line, then a comment in the style of the C-language /* … */ is multi-line|
Listing 3.9 demonstrates the use of all three types of comments from Table 3.1.
Listing 3.9. Comments. File comments.php.
<?php /* Demonstration of different types of comments in PHP programming language */ echo 'Hello'; // this is a comment echo 'Hello'; # and this is a comment
Naturally, PHP comments act only inside limit tags
<?php ... ?>. That is, if the comment characters are outside the delimiter tags, they, like any text, will be displayed by the browser (Listing 3.10).
Listing 3.10. Comments are valid only inside <?php and ?>. File into.php
<?php echo "Hello<br />"; // РНР comment ?> // this text will be displayed by the browser ---------------- <!-- This text will not be displayed by the browser because it is enclosed between characters that are HTML comments. However, it can be viewed in the source code of the HTML page. -->
Comments can be inserted not only after the semicolon, but also in the middle of the expression (Listing 3.11).
Listing 3.11. The comment in the function argument list. File position.php
<?php echo strstr( // we will look at this function later "Hello, world", "H");