PHP commenting guide

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

  1. RHochstenbach

    RHochstenbach Administrator

    Likes Received:
    Trophy Points:
    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:
    <!-- 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.

    // This a single-line comment.
    // This is another single-line comment.
    /*  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:

    <!-- Comment inside HTML code -->
    // This is a PHP comment

Share This Page