Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
PHP was designed to make building web pages easier, so let's put these newly learned skills on the web. I've included the HTML and css we'll be using to include the PHP applications we've written on a website.
Treehouse Course: Introduction to HTML and CSS
-
0:00
[MUSIC]
-
0:04
Up to this point, this course has strictly used PHP, but
-
0:08
PHP was designed to make building Web pages easier.
-
0:12
So let's put this on the Web.
-
0:14
I've included the HTML and CSS we'll be using for this course, but
-
0:18
you should be familiar with how HTML and CSS work.
-
0:22
If you haven't gone through our introduction to HTML and
-
0:25
CSS course yet, check out the link in the teacher's notes.
-
0:29
Click the Launch Workspace button to launch a new workspace with
-
0:33
all the files that we'll need for this section.
-
0:36
In the new workspace, we see an index.html file as well as a css folder
-
0:42
with styles.css and an image folder with a couple images.
-
0:46
These are the files that make up the basic Web page we'll be working with.
-
0:50
You'll also see the php files we've created throughout the rest of
-
0:53
this course.
-
0:54
If you click on the Preview button, the icon in the top right-hand corner,
-
0:58
it will open a new browser window.
-
1:01
This shows our index page.
-
1:03
You'll see here that we have a simple informational page with the treehouse logo
-
1:07
and some text.
-
1:08
If we switch back over to our workspaces, we can open the index.html file.
-
1:14
And we can actually see the code that's displayed on the page.
-
1:18
Let's start adding some PHP.
-
1:21
Let's replace this Name heading on the left-hand side.
-
1:24
We can add a php code block anywhere we want in the HTML by adding the opening and
-
1:29
closing php tags.
-
1:35
Then we put our php code within those tags, nothing fancy yet or
-
1:39
even very useful.
-
1:41
I'm just going to echo my name.
-
1:46
Let's save this file and switch back over to the preview.
-
1:49
When we refresh, we don't see any name at all.
-
1:52
So now let's go view the source.
-
1:56
You'll see the new php code block.
-
1:57
But why isn't our php code working?
-
2:00
Well we haven't told our server that this is a php file.
-
2:03
So it doesn't know it's supposed to do anything special.
-
2:06
Let's go back to workspaces and rename this file from index.html to index.php.
-
2:16
Without the php extension, it's just plain HTML.
-
2:20
Now we can go back to our browser.
-
2:23
This time, we see my name, just like I wanted.
-
2:26
A PHP file can include HTML outside the PHP code block.
-
2:30
And that HTML will be processed the same way an HTML file would be processed.
-
2:35
PHP only executes the code within the code blocks.
-
2:40
Great job, you've now used PHP
-
2:42
in combination with HTML to create your first PHP webpage.
-
2:47
I know, I know, it's really not very impressive yet.
-
2:50
And you could have done this in pure HTML.
-
2:52
Don't worry, I've got you covered.
-
2:54
In the next couple videos, we'll learn how PHP can reduce busywork and
-
2:58
maintenance, allowing us to work faster and be more productive.
-
3:02
Finally, we'll include the other scripts that we wrote and
-
3:05
put all these projects together.
You need to sign up for Treehouse in order to download course files.
Sign up