PHP for the World Wide Web (Visual QuickStart Guide)
I l @ ve RuBoard |
Every programmer eventually figures out that making notes to yourself is a lifesaver when you inevitably need to return to a project to tweak, copy, or fix some code months later. Adding these notes, or comments, to your work helps remind you of what you were thinking at the time, which is not always so evident months later. The computer itself ignores these comments when processing the script. PHP supports three methods of adding comments. There are two ways to comment out one line of codeby putting either // or # at the very beginning of the line you want ignored. You can also use // or # to begin a comment at the end of a PHP line like this: print ("Hello."); // Just a greeting. To comment out one line of code:
Using /* before and */ after a section of code, you can have the server ignore anything from a single word to several lines. To comment out multiple lines of code:
Tip You can comment out just one line of code (as in our example) or several using the /* and */ method. With // or # you can only ever negate one line at a time.
Tip Different programmers prefer to comment code in different ways. The important thing is that you find a system that works for you and stick to it. Those who also do JavaScript programming will most likely use // and /* */ as these are the same in both languages. Perl programmers are more familiar with the # method.
Tip Note that you cannot use HTML comment characters ( <! and > ) within PHP to comment out code. You could have PHP print those elements to the browser, but in that case you will be creating a comment that appears in the HTML source code on the client's computer (but not in the browser window itself). PHP comments never make it as far as a user 's computer.
Tip As text commented out within PHP is not sent to the browser (Figure 1.10), it makes this a good place to leave notes that only the programmer will ever be able to see. Figure 1.10. Compare the code here to that before we commented out the print command (Figure 1.7) and you'll see that the PHP code never gets to the browser. HTML code that has been commented (using <! > ) still appears in the source code but is not interpreted by the browser.
Tip More advanced text editors such as BBEdit will use colors to indicate which code is commented out and which code is not (Figure 1.11). This can be very helpful when working on large scripts. Figure 1.11. If your text editor color codes your code, it makes programming a lot easier. Here BBEdit puts commented code in gray, indicating that that particular code is inactive.
|
I l @ ve RuBoard |