PHP commenting guide

Discussion in 'Web Design & Programming' started by RHochstenbach, Mar 8, 2011.

  1. RHochstenbach

    RHochstenbach Administrator

    Likes Received:
    26
    Trophy Points:
    48
    Just like every programming language, you might want to add comments to provide information about your code to others or to yourself as a reminder. In HTML we can do it like this:
    HTML:
    <!-- This is a comment -->
    PHP uses a double slash ( // ) For a single line comment. For a multi-line comment, start with this ( /* ). You can end the comment with the opposite ( */ )

    Remember that you should only use this inside PHP tags. Outside them (when using HTML), you should use HTML comment syntax. Having an HTML comment inside PHP tags gives an error because PHP doesn't understand this. Having PHP comments inside HTML code will just show it on the screen. Here's an example of PHP comments.

    Single-line:
    PHP:
    // This a single-line comment.
    // This is another single-line comment.
    Multi-line:
    PHP:
    /*  This is a multi-line comment.
    We can have as much lines here as we want.
    Isn't that great? */
    In an HTML file with PHP tags, it looks like this:

    Code:
    <html>
    <body>
    <!-- Comment inside HTML code -->
    
    <?php
    // This is a PHP comment
    ?>
    
    </body>
    </html>
     

Share This Page