Powered by InterCreatives | Site Map
Search:
NewSourceMedia Popular Tutorials: PHP Javascripts Web Hosting
SoftwareTutorials
CATEGORIES
Job Listings
 
Home / PHP / Beginner

PHP Lesson 2 - Add Comments

Published by: Alexander McLean III View Site


Introduction

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!”
?>


Note:
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!
Summary


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.

Books:
Professional PHP4 Programming
PHP and MySQL Web Development


Next PHP Page:
1  [2]  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32 





Hosting by iPowerWeb.com - 50 Gb for $7.95