Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Commenting code

From: Dynamic Dreamweaver Websites: Creating and Validating Forms

Video: Commenting code

I want to talk about commenting your code when you begin working in PHP, or any type of programming. It's very important to comment your code in order for you to understand two, three, six months from now what you were doing within the pages. As you work in static pages, it's not too important particularly in HTML. So a lot of people moving into dynamic web sites using server side languages, tend not to remember to comment.

Commenting code

I want to talk about commenting your code when you begin working in PHP, or any type of programming. It's very important to comment your code in order for you to understand two, three, six months from now what you were doing within the pages. As you work in static pages, it's not too important particularly in HTML. So a lot of people moving into dynamic web sites using server side languages, tend not to remember to comment.

And it's a very important part of the process to save you time long term. So what we want to do is add a comment within our PHP code block. Now let me show you a couple of things with regards to comments. So I'm going to type out under the body tag, this code creates variables, and prints them to the page. Now this is such simple code.

Prints them to the page. Let me focus on what I'm doing here. So I'm going to make this comment an HTML comment, and DreamWeaver does have a commenting area... This little piece here, where it looks like it's somebody talking is how you apply a comment. This is how you remove a comment. So, if I want to make this an HTML comment, I use the first one. So, I'll go ahead and do that. You can see HTML comments turn a light gray.

Now, what if I put that same information inside the php code block. So this is the opening part of the code block, this is the closing portion, just like HTML has an opening and closing tag. So I'll paste that in. Whoops, looks like I didn't copy, just one second. I'll put a copy in here, and paste. There we go. Now notice what happens in dream weaver, it's telling me there's an error here.

Php can't understand this line of code. First of all php lines have to have a semi colon but in order to make this a comment I could do a couple of things. One is since I have this php tab up in my inset bar. I can go ahead, and if I highlight this piece, notice it say's comment. So I can comment in that manner. Now the html comment is gray, the php comment is orange, and notice I no longer have syntax errors..

So that's one type of comment. Now I'll select that and click the red X. And that'll remove the comment. Now, let me show you the other type of comment you can use in PHP. There's actually a couple of others. But I'll just show you one other. I can also apply that type of comment here. Or I can use this type of comment. And notice that turns orange. And I have no syntax errors. So that's one way to type out a comment.

Let me leave both of these comments in here. Let's save the page,and put it out in the browser. Now you can see your page doesn't look any different than it did before the comment. But what happens to our comments within the source code? This is my HTML comment that's showing in the source code. Any PHP within a PHP code block, the entire code block is stripped out and the page is sent back to the browser via the web server without any PHP coding in it.

So any of your PHP comments are stripped out. So just keep in mind any HTML, Javascript or CSS comments are visible to anybody out on the web. But any server side language code, including comments is stripped out and that all occurs before the page is sent to the user via the web server and the browser. So, that's how you create PHP comments. Now within this course and even within my classroom enviornment we don't always take time to sit and type out the comments.

And for people new to a server side language, you can get in the habit of not doing that, and I would strongly recommend you do that immediately. Think about putting a comment in each PHP code block. I also, if I modify something while I'm working on a website, I put a comment about why I modified it. The date I modified it, and my initials. Sometimes, I even put, depending upon the client, who approved the modification, so it gives you a way to store information within your pages that won't be visible to anybody but you, but that is commenting.

Please assume that we would be putting comments in every code block even though I don't take the time to do it throughout this course. So that's the importance of commenting code. If you can get in the habit of doing it right away, you will be much better off in the long term. So PHP comments come in a variety of ways. You can do it up in here in the insert bar, or you can use this comment. This is known as the Coding toolbar. So those are PHP comments.

Show transcript

This video is part of

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Dynamic Dreamweaver Websites: Creating and Validating Forms.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.