Hey everybody I want to let you know that I have undertaken the grueling task of getting the heck away from WordPress. I was so sick of the problems and updates I had to do all the time. I am now using my ezbloo system and I am integrating all my old posts into the new system. It sucks, but in the end, I will save bundles of time. I needed to keep things simple and that is why I created ezbloo. I'll have more on this later for you guys after I am done with the total integration of my old posts here. So if you are looking for a post and need it faster, shoot me an email and I will make it a priority. [email protected]

In this lesson we are going to assemble a basic website and code it in PHP. In our previous beginner course on lesson #9 we built a website with HTML. I then taught you how to use CSS and JavaScript with those sites. Now I am going to show you how programmers write HTML and more with PHP. We will be using PHP7 in this tutorial. Make sure that you have completed the first 3 lessons so that you will not be lost. 


PHP Features In This Lesson

  1. echo command
  2. strings
  3. variables
  4. include

PHP Files

Here are the php files for this lesson. Click to download zip file. 

HTML Flashback Lesson #9 To Code in PHP

In lesson #9 in the beginners web development course we coded a website in HTML. We then displayed it in a browser to show you how HTML works. We are going to work off of that lesson and put it in PHP.

Section Off HTML

The way to think about this is to section off HTML. Most websites have a header, body and then a footer. So the top part anything above the opening body tag and including the body tag would be part of the header. Underneath the body tag clear to just before the closing body tag would be your main content. Then the closing body tag to the closing HTML tag would be your footer. You can name your files like this in PHP.
  • header.php
  • main.php
  • footer.php

Index.php File And The Include Function

You would then insert those files into the index.php by using the PHP include function. You index file would look something like this.
<?php include('header.php');?>
<?php include('main.php');?>
<?php include('footer.php');?>
 

Variables in PHP

In this lesson we set a variable and stored the menu items in it.
<?php $var='
<ul>
<li><a href="foo.php">Foo</a></li>
<li><a href="doo.php">Doo</a></li>
</ul>';
echo $var;
?>

Conclusion of this PHP Lesson

The object of this lesson was to teach you that you can program something once and use it over and over again in your other files. There is no need to keep writing the same things over and over again. I hope you are enjoying the process of learning to program in PHP. Please share these lessons so we can get the word out. :-)