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
- echo command
- strings
- variables
- 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. 🙂
A1WEBSITEPRO Social Media Pages
Here are my social media pages, lets hook up!