WEBVTT

00:00.890 --> 00:05.270
Okay, so so far we've been only building the command line programs.

00:05.270 --> 00:12.560
So programs that run in a terminal in a command line interface without a graphical user interface.

00:12.560 --> 00:16.880
And we did that to focus on the PHP language.

00:16.880 --> 00:23.720
It's time to change that and use PHP for what it was made for, which is building dynamic websites.

00:23.720 --> 00:29.600
And that means that we are about to build our first dynamic website.

00:29.600 --> 00:36.740
This would be a very small project, but it will teach us a couple of things and you see it on the screen.

00:36.740 --> 00:39.530
Let me describe what we are going to learn first.

00:40.250 --> 00:45.980
So first and foremost you are going to learn how to start the PHP build in server.

00:45.980 --> 00:54.350
So the PHP binary has a built in web server, which means you don't need any external web server to

00:54.380 --> 01:00.850
run PHP websites, at least for development purposes at your own computer.

01:01.090 --> 01:03.700
Then the things that we're going to learn.

01:03.910 --> 01:07.210
We are going to learn about super globals.

01:07.210 --> 01:10.840
Those are special global variables in PHP.

01:10.870 --> 01:12.220
They are predefined.

01:12.250 --> 01:19.330
They don't require you to use the global keyword, and they are available everywhere and you can't override

01:19.360 --> 01:19.990
them.

01:20.110 --> 01:27.040
There is plenty of them, and they contain a lot of information about PHP, about the environment,

01:27.040 --> 01:29.920
about the request and user input.

01:32.410 --> 01:39.250
The next thing I'd like to focus on is actually a concept, not something strictly related to PHP.

01:39.520 --> 01:46.960
And this is to separate the logic of the page, which is this part where we generate data or read data

01:47.080 --> 01:52.150
from the part that is responsible for displaying the HTML.

01:52.150 --> 01:54.040
I think it is a good practice.

01:54.070 --> 01:59.420
It makes this code readable And things are just easier to find here.

01:59.420 --> 02:03.380
So while speaking about this, let's call it Presentation Layer.

02:03.380 --> 02:10.040
We're going to learn about this shortcut PHP way to quickly output the value of an expression or variable.

02:10.040 --> 02:11.750
So this is this equal sign.

02:11.750 --> 02:14.570
Here you don't need to use the echo statement.

02:14.570 --> 02:18.320
And also semicolon is not required here.

02:18.350 --> 02:24.440
And then there is also the alternative syntax for for each loop.

02:24.440 --> 02:29.180
And every control structure in PHP has this alternative syntax.

02:29.390 --> 02:33.800
So you've got the colon instead of curly braces.

02:33.800 --> 02:39.890
And also the ending is end for each not a curly brace.

02:40.610 --> 02:43.490
And about the project itself, it's rather simple.

02:43.490 --> 02:46.340
We're just gonna display the current server time.

02:46.340 --> 02:51.830
So keep in mind that not the time on your computer, it is the PHP server time.

02:51.830 --> 02:53.390
So they might differ.

02:53.390 --> 02:59.740
And then we're gonna to format all the information from the server in a nice table.

03:00.040 --> 03:01.360
So let's get started.

03:01.930 --> 03:05.110
So we start with just the PHP tag.

03:05.140 --> 03:08.650
Let me define a page title variable.

03:08.710 --> 03:12.880
This would be dynamic PHP page.

03:13.870 --> 03:17.290
And I'm going to close the PHP section right now.

03:17.320 --> 03:20.920
So the goal is that on the top we've got the logic of the page.

03:20.920 --> 03:24.310
And on the bottom we just output HTML.

03:24.400 --> 03:31.750
So let me add an HTML tag a head section where I'm going to output this title.

03:33.130 --> 03:35.740
So I'm using this shorthand syntax.

03:35.920 --> 03:37.240
Page title.

03:37.240 --> 03:41.500
And here I don't need the semicolon.

03:43.540 --> 03:48.220
So after refreshing this page we can see the title is already there.

03:50.740 --> 03:51.160
Okay.

03:51.160 --> 03:54.740
Next up let's display the current time.

03:55.010 --> 04:02.390
So maybe that's not the times where we display the current time on the websites, but we are just playing

04:02.390 --> 04:03.260
around.

04:03.620 --> 04:06.860
So here I'm going to call this date function.

04:06.860 --> 04:11.600
It accepts a specific string which is called the date format.

04:11.600 --> 04:18.680
So you can look up the date function in PHP manual because it describes how you can construct a very

04:18.680 --> 04:20.090
specific date.

04:20.090 --> 04:22.790
In this case this will show that day.

04:22.790 --> 04:26.630
Well, this will show the time including minutes and seconds.

04:27.290 --> 04:29.570
So now let's display this value.

04:29.570 --> 04:32.180
For that we need a body section.

04:32.180 --> 04:35.300
So the actual page content.

04:35.300 --> 04:38.870
So I'm just going to say welcome for now.

04:38.870 --> 04:41.270
And let's add a paragraph.

04:41.270 --> 04:45.770
So we're going to say that the current server time this is important.

04:45.770 --> 04:48.200
It is not your time on your machine.

04:48.200 --> 04:58.540
That's the time of PHP Now lets use this shorthand syntax to output stuff and we use the current time.

04:58.540 --> 04:59.320
And that's it.

04:59.320 --> 05:00.550
Let's refresh the page.

05:00.550 --> 05:04.630
Keep in mind you will have to refresh this page every single time.

05:04.630 --> 05:07.210
It's not happening automatically.

05:07.990 --> 05:11.770
Okay, let's zoom in a bit because I'm not sure this is visible.

05:11.770 --> 05:18.730
Now there is a special kind of variables in PHP and this is called super globals.

05:18.730 --> 05:23.470
So super globals are variables that are available globally.

05:23.470 --> 05:26.710
And you don't need to add the global keyword.

05:26.710 --> 05:32.560
They are really available globally and you can't override their value.

05:32.590 --> 05:34.960
They are kind of read only.

05:34.960 --> 05:40.180
That's why they are not called globals, but they are called super globals.

05:40.960 --> 05:45.250
The names of those variables typically start with an underscore.

05:45.250 --> 05:46.660
So you've got cookie.

05:46.690 --> 05:53.160
You've got environment variables, files that are uploaded and others.

05:53.400 --> 05:57.540
For now, let's vardump the server super global.

05:57.540 --> 06:04.260
So as you see, this contains quite some information like HTTP headers.

06:04.260 --> 06:09.690
The the request URI uh server name which is localhost.

06:09.690 --> 06:12.240
Well useful information.

06:12.810 --> 06:22.830
So now we're going to use this server super global and display this information nicely in a table.

06:22.830 --> 06:29.580
So what we want to do here is a kind of information page about PHP okay.

06:29.580 --> 06:37.170
So right below this paragraph let me add a table because we want this information in a table.

06:37.170 --> 06:44.760
Every table needs a header where you have some columns with titles of those columns.

06:44.760 --> 06:49.210
Let's add a row and two columns.

06:49.870 --> 06:53.050
I'd like this text to be in bold.

06:53.050 --> 06:55.150
So we've got the key.

06:55.150 --> 07:05.770
And next up we've got the value after the T head section we've got T body, which as you can guess contains

07:05.770 --> 07:07.270
the actual elements.

07:07.300 --> 07:15.250
Now you're gonna see the alternative control structure syntax, which is not super different, but it

07:15.250 --> 07:20.380
is often used with when PHP is mixed with HTML.

07:20.380 --> 07:22.780
It is more convenient then.

07:22.840 --> 07:31.780
So we're gonna iterate over this server super global and we want both the key and the value.

07:32.500 --> 07:35.050
So this is this alternative syntax.

07:35.050 --> 07:39.760
Instead of using curly braces you're gonna use a colon.

07:39.880 --> 07:41.560
And that's everything.

07:41.590 --> 07:46.820
Now you need to also close this for each loop.

07:46.940 --> 07:51.980
And you do that by typing and for each.

07:54.830 --> 07:55.550
All right.

07:55.580 --> 08:04.580
Now inside let's add a row and two columns that will display the value.

08:04.880 --> 08:14.570
So we basically now need to output the key without semicolons in case of this shorthand syntax.

08:14.570 --> 08:18.770
And as you can guess the value.

08:20.210 --> 08:23.210
I think this should work fine.

08:23.210 --> 08:27.410
So now initially we had this data var dumped.

08:27.410 --> 08:29.480
It's totally unreadable.

08:29.480 --> 08:31.400
Now let me refresh the page.

08:31.400 --> 08:34.250
And this is what we have right now.

08:34.640 --> 08:42.320
The current server time and all the information about the request in a nicely formatted table.
