PHP Programming/html output

There are a few different way you can display HTML using PHP. Generally, you will use the echo command to output something. This will be seen by a web browser, and then it will format it.

Breaking PHP for Output
In addition to using functions such as echo and print, you can also end your script, and anything beyond the end of the script will be output as normal HTML to the browser. You can also restart your script whenever you want after you've closed the PHP tag. Confused? It's actually pretty simple.

Let's say you had a for loop to count up to five and output it.

While I would tend to use templates for larger pages that output a lot, we'll get to that later. Remember how all your PHP scripts start with  and end with  ? Those don't have to be the very start and end of your file. In fact, PHP handles ending and restarting scripting just like if everything between the  and   tags were inside of an echo statement.

Thus, you could do something like this:

This is actually a very common method of outputting variables in a script, especially if there is a lot of HTML surrounding the variables. As I said before, I personally rarely ever do this, as in my opinion, using echo for smaller scripts keeps your code cleaner (and I would use templates for larger ones). However, we want to cover most of the language here, so this is another method you could use.