PHP/Language Basics/Comments

Материал из Web эксперт
Перейти к: навигация, поиск

A comment is text in a script that is ignored by the PHP engine.

   <source lang="html4strict">

Single-line comments begin with two forward slashes (//) or a single hash sign (#). <? // this is a comment

  1. this is another comment

?>

 </source>
   
  


Combine three types of comment signs

   <source lang="html4strict">

<? // This is a simple PHP comment. /* This is a C-style, multiline comment. You can make this as long as you"d like. */

  1. Used to shells? Use this kind of comment.

?>

      </source>
   
  


In PHP, everything between /* and */ is considered a comment

   <source lang="html4strict">

// or # may be used to "comment out" the remainder of a single line: <?php

   $var = "foo";        // This is all ignored
   $var = "bar";        # so is this

?>

 </source>
   
  


Multiline comments

   <source lang="html4strict">

<? /* line1

  - A
  - B
  - C
  • /

print "line 5"; print "Cost: 3.25 + 9.50 + 25.00"; ?>

 </source>
   
  


Multiline comments begin with a forward slash followed by an asterisk (/*) and end with an asterisk followed by a forward slash (*/)

   <source lang="html4strict">

<? /* this is a comment none of this will be parsed by the PHP engine

  • /

?>

 </source>
   
  


PHP comments are usually preceded by double slashes

   <source lang="html4strict">

<? // this is a comment in PHP code echo "This is not a comment." ?>

      </source>
   
  


Php more than single line comment

   <source lang="html4strict">

/* This begins a C-style comment that runs onto two lines */

      </source>
   
  


Php single line comment:#

   <source lang="html4strict">
  1. This is shell-style style comment
      </source>
   
  


PHP supports C, C++ and Unix shell-style comments

   <source lang="html4strict">

<?php

   echo "This is a test"; // This is a one-line c++ style comment
   /* This is a multi line comment
   yet another line of comment */
   echo "This is yet another test";
   echo "One Final Test"; # This is shell-style style comment

?>

 </source>
   
  


shell style comments

   <source lang="html4strict">

<?php

    # Title: My PHP program
    # Author: Tom
    print "This is a PHP program";

?>

 </source>