Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
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.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98775 Viewers
61 Video lessons · 86099 Viewers
71 Video lessons · 69951 Viewers
56 Video lessons · 102204 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.