You will save a lot of time and money if you just remember to write comments as you write your codes. Trust me, you will forget which code goes where and what it does. We all forget. This is a how-to on how to organize your scripts with different types of
In this tutorial you will learn how to organize your PHP script using comments. You may feel it’s unnecessary to write comments in your code; however, comments can save you a great deal of time and money plus help you and other programmers understand your code for future revisions.
If you have not read part one, please do and if you are not working on a php server, we recommend SimpleHost.com for only $7.50 with Unlimited Disk Space, Subdomains, and Emails Accounts.
PHP Comment Examples
For a single line comment use “two forward slashes” (//) or a “hash sign” (#) like this:
// This is a single line comment.
# This is also a single line comment.
Multiple line comments start with a forward slash with an asterisk (/*) and ends with an asterisk with a forward slash (*/) like this:
This is a multiple line comment.
Just remember that the asterisks are always placed on the inside of the combinations.
Combining PHP with HTML Comment Tags
PHP comments, as well as PHP codes are not viewable in the browser window, nor will you find them inside the browser’s view HTML source code. In order to view comments in the browser’s view HTML source code, you must create comments using HTML comment tags.
An HTML Comment tag starts with a less-than sign, exclamation sign and a few dashes (<!–) and end with a few dashes with a greater-than sign (–>). Here are examples of combining PHP with HTML comments:
echo “My name”;
<!– this is an html comment –>
echo “is Alex!”
In the code above I used three blocks of code. The beginning and last blocks were PHP and the middle block was an HTML Comment.
You can also have PHP output the HTML comment like this:
echo “My name <!– this is a html comment –> is Alex!”;
PHP will output this to the browser:
My name is Alex!
The source html code view will look like this:
My name <!– this is an html comment –> is Alex!
If you have any questions, please search or post a question to the forum. You may also want to check out a few of the books listed below.