Practical PHP: Master the Basics and Code Dynamic Websites | Brad Hussey | Skillshare

Practical PHP: Master the Basics and Code Dynamic Websites

Brad Hussey

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
46 Lessons (6h 21m)
    • 1. Welcome to the course

      1:47
    • 2. What is PHP?

      1:24
    • 3. What does PHP do?

      1:08
    • 4. Tools to get started

      7:23
    • 5. Download the course files

      3:39
    • 6. Your first PHP page

      8:00
    • 7. Syntax

      3:17
    • 8. Variables

      3:10
    • 9. More variables

      2:56
    • 10. Defining constants

      3:25
    • 11. Get your hands dirty!

      15:25
    • 12. Arrays

      11:56
    • 13. Associative arrays

      9:52
    • 14. Multi-dimensional arrays

      10:35
    • 15. Get your hands dirty II

      12:07
    • 16. If statements

      8:23
    • 17. Else

      7:18
    • 18. Else if

      9:19
    • 19. Get your hands dirty III

      11:37
    • 20. Comparison operators

      19:12
    • 21. Logical operators

      12:20
    • 22. Arithmetic operators

      8:39
    • 23. String operators

      7:00
    • 24. Assignment operators

      7:54
    • 25. While loop

      6:50
    • 26. For loop

      4:49
    • 27. Foreach loop

      5:20
    • 28. Do while loop

      4:22
    • 29. Intro to PHP functions

      13:17
    • 30. Building custom functions

      7:22
    • 31. Simple arguments

      7:26
    • 32. The final website you'll build

      5:09
    • 33. Final: Basic layout

      11:22
    • 34. Final: Global header & footer

      13:42
    • 35. Final: Copyright hours

      14:21
    • 36. Final: Team members

      17:30
    • 37. Final: Menu

      17:26
    • 38. Final: Understanding $_GET

      1:49
    • 39. Final: Menu items

      15:55
    • 40. Final: Contact form

      8:14
    • 41. Final: Understanding $_POST

      1:35
    • 42. Final: Form validation

      14:02
    • 43. Final: Form validation, part II

      15:31
    • 44. Final: Upload your website live

      4:01
    • 45. Wrapping up!

      1:59
    • 46. Please leave a review

      0:50
12 students are watching this class

About This Class

Practical PHP is a total beginners guide to coding dynamic websites with PHP so you need no prior knowledge or experience with PHP — although, it is a good idea if you know some HTML & CSS. Learn by doing and creating real-world examples, including a restaurant website at the end of the course — complete with an interactive food menu, and team members!

I think you're going to love this course, and you're going to especially love what you're going to learn. When I first started learning PHP, I couldn't wait to start implementing what I learned into my websites! I think you'll feel the same. Join me today!

Transcripts

1. Welcome to the course: Hey, everybody, welcome to code dynamic websites with PHP. My name is Brad Husi and for the next little while I'm gonna be your personal instructor and I will be teaching you how to hand code PHP. This course is a total beginners guide to coating your very own dynamic websites with Ph. B. So you need no prior knowledge or experience, Although it's a good idea that you know some html my beginner's guide to build a website from scratch with HTML and CSS will teach you everything that you need to know. My approach with this course, like many of my courses, is to take a practical hands on approach. While there will be some theory involved, every single lesson requires you to get your hands dirty and exercise what you've learned in that specific lesson. I find this to be the best approach because you're able to retain much more of what you learned and therefore get up and running and maximizing your practical knowledge of PHP quickly. So I learned PHP well. PHP is a very powerful scripting language used by millions of websites. Some of the most popular websites and frameworks utilized PHP to build their dynamic websites. PHP works very well with HTML and therefore will allow you to start coding dynamic websites quickly without having to learn some of the more complicated scripting languages out there . I think you're gonna love this course and you're going to especially love what you're going to learn. When I first started learning PHP, I couldn't wait to start implementing what I learned into my websites. And I think you'll feel the same way. Also, I'm excited to be offering this course absolutely free for three reasons. One, I don't want a purchasing decision to get in the way of you learning what I have to offer in this course to I want as many people as possible to be able to access the content. And three, I want to give you learning materials so good that it should cost money. So I invite you to join me in learning how to code dynamic websites with PHP. Let's do this 2. What is PHP?: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called What is PHP? Well, PHP is one of the most, if not the most popular service side programming language on the Web today, with more than 240 million websites using it. As of January 2013 according to Wikipedia, websites like Google, Apple, Facebook and YouTube utilized PHP. Popular content management systems like WordPress tripled dumela and Expression engine all rely on PHP. BHP stands for hypertext pre processor. I know, right? I don't get it, either. PHP can be used as a standalone programming language to create robust applications, or it can be used with in HTML code to create dynamic websites, which is the goal of this course. PHP runs on a server and in order to use PHP on your own computer when developing a website , you'll need to have a server installed on your machine. Don't worry about this part. It's quick and painless to get set up, and it doesn't cost you a penny. I'll be covering the tools you'll need in an upcoming lecture. Also, I will be frequently referencing PHP dot net throughout the duration of this course and I recommend you bookmark it for easy access. Stay tuned, because in the next lecture I'll be giving you a quick run down of some of the cool things PHP can do. See there. 3. What does PHP do?: Hey, have already welcome back to code dynamic websites with PHP. This lecture is called What does PHP do? Well, PHP could do a whole bunch of really neat things, such as access information typed into a Web form and do something with it, like send an email navigate to a specific page based on the info submitted in the form. Create a user account, log a user in etcetera. Find out what browser and operating system your visitors are using. Display alternate versions of a Web page to users who are using mobile devices or specific browsers like Internet Explorer. Do math and, most importantly, in my opinion, create templates for your website so you don't have to hand code your headers, footers and sidebars for every single page. There's so much that PHP can do, but I don't want to go into all the details right now because I'd like to show you by jumping right in. I think that it's much more fun that way. Next up, you're going to need to have some specific tools in order to get the best out of your PHP learning experience, and I will cover those in the next lecture so we'll see there 4. Tools to get started: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called Tools to get started as I mentioned before because PHP is a server side programming language, it requires a server in order to run. Now, I don't mean a physical server that costs thousands of dollars and takes up an entire closet. I mean, virtual server that can run on your computer. The great thing about this is that there are a number of great free options out there. If you're on a Mac, I suggest using ma'am, ma'am stands for Mac Apache, my SQL PHP. However, they've recently developed a beta version for Windows. So the Windows version stands for my Apache, my SQL PHP. If you're on a Windows machine, I recommend trying the windows version of map as well. Keep in mind that it's in beta at the time of the recording of this video, so there may be some bugs they're still working out. Alternatively, both Mac and PC users can try something like amps a MPP s. But I will be using ma'am, so it might be easier for you to follow along using map as well. So in the interest of full disclosure. Please keep in mind that some of the following resources that I'm about to talk about are my affiliate links, and I'll earn a small commission should you decide to make a purchase with them at absolutely no cost to you. However, keep in mind that I either have thorough experience with the following tools and websites or have heard great things about them, and I am only recommending them because they have helped me succeed in my business or are incredibly useful. Don't spend any of your money on the products or resources unless you think they will help you or further you in your learning experience with me. So my most recommended tool is a code editor. You're obviously going to need a code editor for this course. And if you're serious about coating or you want to start out with a solid tool to code with , I reckon I strongly recommend coda to for Mac. It has a beautiful user interface with tabbed navigation. The super sidebar on a simple layout. The features are totally outrageous and extensive, with code folding smart, complete auto indentation get integration built in terminal. I called support just to name a few the features. They seem to be endless with coda to I Use CO two for all of my courses and tutorials and also for my projects, personal and professional. And if you decide to use Coda to as your code editor of choice, it would greatly benefit you when taking my course is this one and all my other ones. The price of the editor weighs in at $75 us. But there is a seven day unlimited trial, which should be plenty of time for you to complete this course. However, there are more options out there, and here are a few you might consider. So for both Mac and Windows, there is something called text tastic, a minimal code editor that allows multi tasking, auto code completion, syntax, highlighting and mawr. I've never used it personally, but it seems to be a popular choice. The great thing about this one is it's only 5 99 us. There might also be a free trial with this one as well. I'm not entirely sure. Next up. Sublime text. It's a full fledged code editor that features side by side mode for comparing documents full screen mode, a whole bunch of other great features as well and one of the best code editors out there. And if I didn't love coda to so much, I would probably use sublime texts. The price tag for sublime text is $70 but it comes with a free trial. Now four Mac only users There is Espresso by Mac Rabbit. It is a sexy code editor that looks beautiful and performs just as beautifully. Espresso claims to turbocharge your workflow. It features extensive language support, powerful smart snippets, code folding, real time, live styling and so much more Espressos. Price tag is $75 us, but it has a free trial as well, so worth checking out. It's very similar Dakota as well. So if you want to try espresso up, then it might work really good with this course. All right, so text Wrangler. It's a simple, bare bones text editor and handles code quite well, but is meant for hand coding with no frills. That means there aren't really any features. It's a good practice to learn how to hand code the no frills way. If you're just starting out with learning how to code Ah, and the great part is it's free as well. There's also BB Edit, which is the big Brother to text Wrangler B B ed. It has a much more impressive feature set, much like the features listed in the code editors I previously mentioned. So next you're obviously gonna need a browser. Ah, I suggest using a modern browser like Google Chrome, Apple Safari or Fire Fox. I will be using Google Chrome throughout the course, so it might be helpful to follow along domain names and Web hosting, so they're not required for this course. But it is a good idea to have a domain name and hosting account ready as later in the course, we will be touching on how to upload your website live on the Web. If you don't have a domain when posting. Ah, and you don't want to have it. That's OK. So my most recommended hosting provider is just hosts, and you can sign it for just host at Brad has it out. See a slash just host. I use them for all of my websites and have been a happy customer for nearly seven years Now I recommend these guys all of my clients, my students, my family and my friends. And if you're looking to start your very first website or are looking for a reliable hosting provider, then you found them. You get a free domain name for life, great customer service on limited domains. On the minute email accounts, unlimited gigabytes of space. It seems like there's unlimited everything and an any time money back guarantee. But by far, my most favorite part is you can set up a Blawg website in minutes with one click WordPress install. It's quite impressive. I have a video on it. You can check it on YouTube. These guys are awesome. Now, if you're looking to purchase a domain name, I recommend Go Daddy, and you can sign up or get a domain name at Brad. Has he got see a slash go daddy, I use Go Daddy to purchase all my domain names, and it's one of the best, if not the best website to find and purchase all of your domain names. So learning HTML and CSS. If you're unfamiliar with HTML and CSS, I strongly recommend you pick up some of the basic skills before going forward with this course, as you might get lost in some of the concepts without HTML knowledge. Lucky for you, I have a total beginners course called Build a Website from scratch with HTML and CSS, and it will get you up and running quickly. I also give you 50% off if you use the coupon code dynamic and PHP well, that's all for the important tools and resources. At this point, I recommend book marking my Resources page at brad Husi dot c a slash resources for future reference as I frequently update that page with the helpful tools I used to make my life a little bit easier. Thanks for hanging in there. Next up, we're diving into PDP basics. See there. 5. Download the course files: Hey, have already welcome back to code dynamic websites with PHP. This lecture is called the course files either in the extra section or in the description. If you're viewing from YouTube, I provided a link to download the course files. The course files are the heart of this entire course, so don't forget to download them because you're going to require them in order to follow along and for future reference. All right, so when you've downloaded your code dynamic websites course files, you will get a folder that looks like this, and it is called code dynamic websites. In the folder, there are going to be a Siris of numbered folders from one through 26 1 being the first page, the first PHP Pedro code and 26 being the final PHP Web site. You're gonna build using what we've learned throughout this entire course. In each of these folders, there are a series of PHP pages, so we have index and practice of PHP. And as you get further and you'll see that there is another file called Final that PHP, everything's gonna make sense with these files as you go through each of the lectures as I try my best to be very clear about when you should be using these files and how you're going to use them in the next lecture, I explain how you're going to be using this code. Dynamic Websites Course Files folder to assist in your learning because technically, this folder is a website as well. It's a PHP Web site, and it requires a server to run. It looks like this in the Web browser. It's a plain old directory showing all the folders here, and basically all you need to do is just click on them and you'll be taken to the first lecture. For example, in this case, I go back and click on the second. What variables? I'm taken to this nice Web page that I've coated and designed so that you could follow along with the lecture you can read through. Watch the video, and then you can go ahead and hit next lecture toe. Learn more about the next lecture. As you go further and further into the course, these lectures will get increasingly more difficult, and they're going to start engaging you. So, for example, you'll see here if I go to here. We have to get your hands dirty lecture and I'm showing your final example. And then I give you a chance to build this yourself. Obviously, you need your code editor to open the PHP file to edit it. But then you can go ahead and check out your example and see if you get the same result as you go through. You'll see more and more of these final example and practice versions. The practice dot PHP file in each of these lectures is gonna be the sandbox where you're gonna build what is in the final that PHP page. So, for example, like here, here's the lecture. This is index PHP. Final example as final dot PHP and your example is practiced that PHP and that is what you'll be using to build each of these mini kind of fun programs. Using PHP and you'll get further and further down will get harder and harder until you get to the last folder here called Final. And it looks different because it's actually in the structure of a standard PHP website or a very basic PHP Web site. We have a series of PHP pages and images folder and includes folder using different things here. And this will all make sense as you go through and learn PHP. So hopefully that makes sense to you, and I'm really excited to teach you some PHP. Let's do this. 6. Your first PHP page: have already welcome back to code dynamic websites with PHP. This lecture is called your first PHP Web page, and in this lecture, we're gonna be doing just that, starting your very first PHP Web page. But before we jump right in, we need to do a couple things in order to make sure we are ready. So by this point, you should have downloaded and installed a virtual server. So either ma'am for Windows or Mac or amps or whatever other virtual server you decided to go with. Go ahead and open up your virtual server. In my case, I will be using ma'am for the Mac. If you're using the same, then this should be a breeze for you. Hopefully for the other servers, it's the same. So you'll see a screen that looks like this little box, and it gives you a couple options. You'll see things like status. Apache Server, my SQL server. A couple of red lights, meaning nothing has started yet. A couple options here, but what we're gonna want to do is click on preferences because what we want to do is change Apache, the document root of Apache, so that we can direct that to our course files because our course files is an actual website, even though it's a bunch of folders with PHP pages and everything. For your reference, it's actually a website as well, so that you can start it up and look at each of the individual documents as we're going through the course. So click Apache and then select, and we want to select our Code Dynamic Websites folder, that course files that you downloaded and then click open. And then that should be your document roots. So we want the code dynamic Web sites folder toe to be the actual document root hit, okay, and then start servers, and this should fire Apache and my SQL. At this point, you should be able to open up your browser of choice. In my case, I am using Google Chrome and if you type in your address, bar local host. Port eight. A eight. When I say port, I mean the colon, that's that's Web Speaker programmer speak for for this so local hosts port 8888 then hit, enter or return, and you should be at the index or the document root of your course files now, Hopefully for you. If you're using a PC or a different type of machine, your port is the same. You can check here in your map settings under ports. Make sure your Apache port is 8888 hit. Okay. And you should be good to go. Local host Port 8888 And now here is Thean decks of your course files. You can see everything in a folder are in their separate folders. So the first thing we want to do is the first page. If you click on first page, you'll be taken to a page that just says Hello, world. Now, I know it's not very pretty or anything, but this is actually a PHP page, and we're using PHP to print this text on your browser window. Now I'm gonna show you how to do that. Open up your code editor of choice I am using coded to and then open your code Dynamic websites course files in your code editor. Choose first page and click on index. That should open it. And you should see a very simple little PHP page. It has HTML. You'll be familiar with this because you should probably know a little bit of HTML. And it has all the basic HTML structure for a simple HTML page. We have a title, but there's something here in the body that's quite curious. And that is PHP, my friends. You're going to be very accustomed to this syntax by the end of this course. So if it looks a little scary right now, by the end of it, it will actually look quite simple and pleasant. At least for me. It's pleasant. I quite like this anyway. So let me explain this just a little bit to code PHP you need to have. First of all, the file extension needs to be dot PHP in order for your Web browser to render it as a PHP page. Of course, you need to server to run it, and that's why we're using man. So in my PHP page, I can use just HTML. But I can also use the PHP tag. And in order to write PHP, you need to have your opening PHP tag, which is three opening bracket question mark PHP and then to close it, you use the question mark and a closing bracket in between there's where you code your PHP . In this case, we're using the print function and print just spits out text or whatever you want in between these brackets and strings. So we're just printing hello world. And now, if you were to view that back in your browser, you can see hello world and your source code should just look like this html Head title body. Hello world. Very, very simple. So if you want to try this, I have provided in the first page folder something called Practice Stop PHP. Go ahead and click that. Basically, it's the same thing, minus the PHP code. So if you want to try your hand at your very first line of PHP, go ahead and remove the HTML flag. Here. The comment and code, your first bit of PHP. So start off like this opening PHP tag. Make sure to close it in between here, let's do the print function and then you have the parentheses and then make sure to close that function with a or ended with a semicolon. In between here that's at a couple strings, and basically you could just type whatever you want. Save that now go back to your browser. Local host. Port 8888 But change at the end of Owen first page. Change that to practice dot PHP and you should go to your practice page. There is hello world just to make sure that it works. Maybe let's change this. Hello, friends Refresh. There does. So that is your first PHP practice page. Let's do a quick little review just so you're not lost at this point, remember to fire up your virtual server in our case or my case it is, ma'am. Under Preferences and Apache. Select your document root and make sure it is your course files. Also make sure that your ports are set to 8888 for the Apache port in your code. Editor, open up your course files Code Emmick, Coach Dynamic websites under 01 1st pages is our very first lecture here, and you want open index. You can view your through the code there in your browser. Local host Port 8888 should look like this. Click on first page. It'll open the index. Once you've coated your practice page, you could just navigate to practice up PHP and there is your code. Bam! First lecture. All right. Good job, guys. We'll see in the next lecture where we're going to start to learn a little bit more about PHP syntax. Alright, See there. 7. Syntax: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called PHP Syntax. And in this lecture of gonna learn about the basic syntax of PHP, there are a few things that you should know. What PHP syntax. I will be using the w three schools dot com Ph B syntax Web page to show you so. PHP script is obviously executed on a server like ma'am, and a PHP script can be placed anywhere in the document. In our case will be using HTML documents in the Peach P can be anywhere. It's good to note that PHP scripts always start with this opening bracket. Question what PHP and always end with question mark and closing bracket. So it looks a little bit like this. Obviously, the default file extension for PHP files is dot PHP. That's why you see, in our code that we just worked on in the previous lecture, we have index up PHP and practice dot PHP those air PHP files. Therefore, the extension is dot PHP. Here's an example of how to use PHP. It's very similar to the one we used in our first page practice PHP. So we're just having, Ah, an echo statement here within a couple of PHP tags. You can also do comments in PHP, just like every other programming language. Html CSS JavaScript above a little blah, blah and they look a little bit like this, so there's a single line comment with two forward slashes. There is an alternative version of a single and Comment, which uses a pound sign, and you could do multi line comments with a forward slash asterisk. And then you write all your stuff in the middle of it, and then you can do asterisks and forward slash. Let's talk a little bit about PHP case sensitivity, so user defined functions like if else, while eco print those types of things which will get very I don't expect you to know anything about that right now. They are not case sensitive. So, for example, in these three echo statements, you could see they're using a bunch of different ways of using the case sensitivity. So all upper case, lower case and a mix of both, and they all echoed the same thing. So this means it is not case sensitive, so the user defined functions are not case sensitive However, on the flip side, PHP variables are case sensitive. So, for example, in these variables, this variable here we're using color equals red. So if you were to echo that color, this one would actually print the color. This one would not because there is no variable that is set with all caps. And this one would also not display anything because there is no variable that looks like this. So this is case sensitive. So that was the super fast, super quick rundown of PHP syntax. It's ah, it's very simple, but kind of boring. And you're gonna be learning it as we go. So that's why I didn't want to touch too much on it. So let's get our hands dirty and jump into the next lecture, which is PHP variables. See, they're my friends. 8. Variables: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called PHP Variables. In this lecture, we're gonna be covering thea absolute basics of a PHP variable what types of variables there are and what they're meant for. If you'd like to follow along using the course files that you downloaded just a couple lectures ago, you can go ahead and open your code dynamic Web sites folder and we are currently in 02 variables. If you were to open index dot PHP in your code editor, you would just see a bunch of code and html. But if you go to your browser and you navigate to local host Port 8888 then click on 02 variables. You'll be taken to the Web page that this lecture is based on. There it is. Think of a variable as a bucket, literally a bucket. That bucket can hold stuff in it like food or dirt and PHP. Variables are buckets, but instead of holding food or dirt, it can hold information like numbers, text, images or logic. All you need to know at this point is that variables are buckets that store information for later use. We'll get to how we actually use the variables in an upcoming lecture. The basic syntax of variable is a dollar sign directly followed by a variable name using text with no spaces than an equal sign, followed by the contents of the variable ending with a semi colon. There are four basic variable types, and each type of variable or bucket is meant to hold specific information. First is called Boolean. A boolean variable specifies a value of true or false and looks like this. So in this variable, you can store a simple, true or false. So that's all you need to know about a 1,000,000,000 variable right now. The second is called an integer, an integer variable is any whole number like one or 2940. The third type of variable is a floating point, and it's usually a fractional number with a decimal like 104 decimal 87 or 1.5, and the last is a string. A string is a simple text that must be enclosed within double quotations or single quotations so you could store something like the word Subaru or drum set And that's it for this lecture. Just the four basic variable types in PHP. I wanna make sure to keep each lecture in small, bite sized chunks, so it's easier to digest each new bit of information. So in the next lecture, we're gonna be diving a little bit further into PHP. Variables. If you're using this Web page in your course files, then you could just scroll to the bottom and hit next lecture. Or, alternatively, you could just navigate to local host Port 8888 and click on 03 more variables, so see in the next lecture. 9. More variables: Hey, already welcome back to code Dynamic Websites. PHP. This lecture is called more variables in this lecture, we're gonna continue from where we left off in the previous lecture, which was PHP variables. And we're just going to cover a few more examples of some PHP variables as usual. Feel free to follow along using the course files that you downloaded in your code Dynamic Websites folder were in 03 more variables. What I suggest doing is navigating to local hosts. Port 8888 I think I was right. 8888 03 more variables or you could just click on 03 more variables right here Or, if you are on lecture to you could just click the button here at the bottom. Next lecture. I'm giving you a lot of different ways to follow along. So if you just want to keep it simple, keep the local hosts website for the PHP course open and just keep following along by pressing next or previous lecture. All right, so let's jump in. All right, so here's some mawr examples of some basic variables. So right here I have my name or my underscore name equals Brad and Brad is a string because it's just text and it's between. Two double quotation marks have ended it with a semi colon so that I can add another variable below here, which is my underscore Age equals. And this one is, um, an integer. So it's just a whole number 25 and I have another very well here, which is a string favor. Underscore color equals blue Sanofi wanted display those variables on the page and some sort of meaningful way. I could use the PHP print function so it looks a little bit like this. Used the opening and closing PHP declaration, and I have the print to function and inside of after print. I have, ah, a opening bracket and a or opening parentheses and a closing parentheses. Within that I have a string, and then I'm just writing some text. But watch this so my name is, and then I'm displaying where I'm typing the variable my name. And then I used in each meal break tag to break it onto a new line. I'm my age years old and like the color favor color. So now PHP will render that and spit out the following. So my name is Brad. I'm 25 years old and I like the color blue. So pretty cool. Hey. All right, so that's it for variables. Right now, we will be using variables a lot throughout the entire course. So don't worry if you feel like this wasn't enough because there's a lot more to come. So seeing the next lecture where we talk a boat, Constance. Alright. See there. 10. Defining constants: Hey, everybody, welcome back to code dynamic Websites of PHP. This lecture is called defining constants. In this video, we're going to be briefly covering PHP Constance and how they differ from PHP variables as per usual. You could follow along in the code dynamic websites course files that you downloaded a while back. We're in 04 defining constants. Alternatively, you can in your browser navigate to local host Port 8888 Or, if you watch the last video, you probably saw the little snippet at the end and said, Click next lecture. And that would have taken you from more variables to defining constants. All right, so let's jump in. So a constant is similar to a variable in the sense that you can store information in a key word that can be used throughout your Web page. So a constant is kind of like, ah, bucket. Like the variable. However, the value of a constant cannot be changed, unlike a variable. So in the variable bucket, you can swap out what you want that bucket to hold. So if you know if one variable is holding one string of text and then later on down your page or ah, later on in your code, you want to change that variable and reuse it, repurpose it half some different content held within the variable. You could do that, but with constants. Once you define what the constant is, you can't change it. It is what it is, so it's literally constant. It's also worth noting that constants are case sensitive and are written in all caps. By convention, they don't have to be. But that's the convention, so you know that it is a constant. It's just easier to differentiate. So here's how you define a constant in PHP. So obviously, within your Ph. P Declaration, I've removed it from this line just for ah, so it looks easier on the eyes. You you type out, define open it with a opening parentheses, close it with a closing parentheses and obviously a semi colon. In between that, the first argument right here in between a string or two quotation marks, you would write what the constant is called. So, for example, in this example, I wrote Title is going to be what the constant is called. Then you put a comma, and then the second argument is within strings as well What you want the constant to be so the value of the constant and in this case, defining constants. So to display a constant, the constant on your page, you can echo it using PHP like this. So here's your PHP declaration. I'm using the echo function, and then you write the constant just all in all caps without this string and then ended with a semicolon, so this will actually spit out the text defining constants. So this is a very mini lecture because in the next lecture were actually going to, as I like to call it, get your hands dirty and try out what you've learned so far. So at this point, you've learned towboat variables and constants. So I'm gonna I'm gonna get you to actually try to to use thes ah, to use these things that you've learned and put it into practice so that it actually makes more sense. So I'll see there 11. Get your hands dirty!: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called Get your hands dirty. And what I like to do in thes specific types of lectures is to actually get you to dive in and put into practice what we've learned so far. So in our case, we've learned a little bit about variables and constants in PHP. So very simply, I want us to jump right in and our code editors and start coding Cem Petri variables and constants and see how it works. So at this point, you should know the drill In your code dynamic websites, course files, you should be able to follow along. And we are currently in 05 Get your hands dirty. You should also open up your browser and go to local host support 888805 Get your hands dirty. You can also use the navigation buttons and the bottom of every lecture to follow along. So here we are in get your hands dirty variables and constants. This is the final example of what we're going to be building right now. And ah, you can see here I'm spitting out what looks to be just some plain static texts, but it's not. It's actually dynamic texts. Ah, and we're using PHP to program it. So, for example, today's date may 6th 2014 for you, obviously, because you are from the future, it will. It will not be May 6. This date is dynamic and is the date that is right now for me. The date that I am recording this video, my name Brad. Amusing PHP to spit out a string of text, My favorite color blue and my age. This is also another really cool one, because this is the age that I am at the time of the recording of this video, you are talking or listening to 26 year old Brad from the past, so pretty cool. Um, there's a button here that says Check out your example. If you click on that, you'll be taken to a practice stuff PHP page that looks pretty but is empty. And these empty spots are where you're going to use your PHP coding skills. You've learned so far to do the lesson, and you will be able to find that I'm just gonna go back to the final example here in your code, editor. So make sure to open up your code editor and open up the code dynamic websites. Um, folder in your code Editor of choice. Mine is coda to you should probably know that at this point, if you are a regular student of mine, so I'll be using Coda to So we are in 05 Get your hands dirty. The index file is right here, but we're going to be working in the practice dot PHP file. Feel free to look at the index file to see what it is that I coded. And in the practice of PHP files where you're gonna be working. So let's just jump right in. So, first of all, you need to within your PHP script right here. I have given you a few directions with some comments. Define a constant. So, like we just learned in the previous lecture, how do we define a constant well, firstly right? Define opening and closing parentheses. We're gonna need a string in there for the first argument and another string for the second argument. So this is kind of the skeleton of the define when you're defining a constant in here we want to define our first constant. So we're gonna define title, remember all caps and let's call it well, variables and constants so variables and constants. So here we go. That is our first PHP constant. We've just to find it, and it should look just like this. Now on under here you will add your variable. So the variables that I've used here in the index the final index up PHP. I'm using my name, favorite color and birth year, so we should probably use those as well. So let's add the my name variable in our string. Let's add your name on a new line. Let's add a new variable and that was favor color because I'm Canadian, I'm spelling it the correct way, and my favorite color happens to be blue at the time birth year and just type out your birth year as an indicator doesn't need to be in a string. There you go. So there are your variables and there are your constants. Next up, I have a little flag here saying, used THP to calculate the difference between your birth year and this year to show your age dynamically. So how do we do that? Well, we have to set some more variables. But first, let's just talk about this big mess of text I have right here in the index up PHP file. So when using the date method, PHP has similar time zone where the server resides in orderto output, the correct our and date for that geographical location. The date underscored default underscore time underscore Set method takes a string that locates the server. The list of supported time zones could be found at this website right here, and then you can set the method for your time zone. So date default times on set Canada Slash Mountain Because I am in the mountain time zone now you don't have to do this because we're just splitting the year. So for the most part, it's PHP is gonna figure out that the current year is whatever the current year is. It may be off by I don't know ah, few minutes or maybe a few hours or something once the time changes ah, and flips into a new year. But you don't have to put this if this confuses you and stresses you out, forget about you don't need to worry about right now or if you're curious. That's great. Go to this website and just set your time zone right here in the date Default time zone set method. So I'm just gonna copy this. I'm gonna paste it below here to set the default time zone for me Now below here. We need to set some more variables. Now, let's set a variable and call it today. So what is today? Well, you can find out what today's date is in PHP by using the date method right here and to display the date in the way that I want to see it I need to use. And it might look confusing capital f your case J comma. Why? So these right here will spit out the month, the day and the year. Now you can find these at this website right here, PHP dot net. Um, I will be referring to PHP PHP dot net a lot because it's a really good resource for PHP, obviously, because it is the official resource and I am going to the date method to find out the parameters that you can use to spit out some text. So right here, you can see here's the options for the day. So lower case, D capital, D. J and L. And this is the example returned and then so on and so forth. There's a week, month, year time. So feel free to go through that. And you can use any of these letters these formats and put them within your string but between the date method. So in our example, we're using F J comma. Why? So it's gonna be the month the actual month, like, say, January, not 01 day and years of the full year. Okay, so, date, here's the date method gonna put in my strings. You could put single quotation marks or put double quotation marks. I'm just gonna use single quotation marks. So we need the 1st 1 which is F then Jay comma year. So we just set the variable today. Now we need to set another variable. And that was this year. So what is this year? Well, we can use the date method again, and we just want to store the year in this variable using the date method. And so we should know how to do that just by putting capital. Why in the date method? So now the today variable has today's full date, and this year has today's year or this year's year. Next up. We need to use PHP to calculate the difference between your birth year and this year. So I'm just gonna move this flag here. The comment flay below here cause that's actually the order that we need to work in. And we're going to calculate my age by doing a little bit of maths. A peach pecan do math. It's really cool. So my age and in parentheses, so you can set a variable and the value of the variable can be a mathematical equation and store it in that variable. So in parentheses, we want to say this year, so right here, this variable this year minus birth year. So let's type that up. So the variable my age equals a little bit of math here. So the variable this year minus today. Sorry, birth year. So that will take this year. So in my case, 2014 minus it by the birth year 1988 end This variable will have my age my dynamic age because this is a dynamic variable using PHP and that will actually have my actual age using math that is always up to date based on the year. So save that. Make sure you're saving this. If you were to check this out in your browser now and remember to check your final example , nothing would show up. There's nothing here because all you've done at this point is set your Constance and your variables, so there's actually nothing here to display. So we did a good job so far of, you know, defining her Constance and adding our variables, but we haven't actually done anything to display them. So that's why down here in the actual HTML, you can see I have some HTML comments reserved just for you to put your PHP constants and variables to see what happens. So this is how PHP kind of works. You can have a separate PHP section in your HTML, but you can also pepper your PHP. I like that pepper your PHP throughout your html. So in this case, I have page title, so let's ah use PHP to display the page title. So, Pete, uh, page title is gonna be a constant. So we have the constant up here. So we know how to do that by going PHP. I'm gonna close PHP so I don't forget. And in here, we're going to say echo and title. Remember, you don't need to put that in strings. This is a constant. So you just need to just write it out like this. So get your hands dirty. PHP Echo title. So now in your browser, you will see get your hands, dirty variables and constants. So that is using a constant pretty cool moving on. So in the H one, we're going to do the same thing. So PHP Echo title. We're gonna echo that constant. Let's check it out. Get your hands dirty variables and constants, Lou that So that is dynamic using a PHP constant moving on. So in the sandbox, we have today's date. We want to display today's date. So do we have a variable for that? Yes, we do. That is today. So echo that using PHP and we're in a echo today. Say that Check it out. May 6 2014. So there you go. That is today's date for me. Yours will obviously be different. Let's move on to my name, so we have another able for that. Stable. Some PHP echo my name, say that. Check it out. There's your name now my favorite color. Replace the HTML flag or comment with your favorite color, but using PHP that would be favor color. There it is. Let's check it out. Cool. Last but not least, my age. Here we go. PHP echo my age. So here's what the math comes in. This variable should have this math. Check it out. 26. Boom. There it is. So you're should be different, obviously, because we're different people when we have different ages and we're currently living in a different time. Ah, and there's one last little thing down here you can see just a copyright sign in a dash. It's kind of empty down here. Well, that's where I want you to try out. Adding something that you quite often add in PHP Web sites is a copyright section with the date and the name so say, for example, we want to display this year. We have a variable for that PHP echo this year and PHP echo your name. You're my name. Say that. Check it out in your browser. There it is, covering 2014. Brad. So pretty cool. Let's do a quick little review in your PHP page practice up each. We under get your hands dirty. We set up our PHP script here, and we defined a constant, added some variables, strings and integers. We set the date default time zone optional, but if you want to do it great, we use the date method toe. Add that today's date and today's year or this year, and we used PHP to calculate the difference between your birth year and this year to show your dynamic age. Then we spit those things out using PHP echo and looks like this. So here's your example. Here's the final example. Check out your example. There it is. Perfect. Good job, guys. I'll see you in the next lecture. 12. Arrays: Hey, have ready. Welcome back to code dynamic websites with Peach P. This video is called PHP arrays. And in this lecture, we're going to be starting to cover PHP a race and how you can use them to supercharge your PHP coating. All right, so in your code dynamic websites course files, you should be able to follow along in 06 a raise. And in here we have three different PHP files, which is different from the previous five folders. We have index dot PHP, which is the the home or index page of the arrays lecture. We have practiced up PHP and final that PHP. I want to show you what the Web page looks like in our lecture. So local host port 888806 a raise. You can check up the final example which will take you to final dot PHP and you could check out your example which takes you to practice Stop PHP. So we're gonna be coming back to those momentarily. But first, let's go back to the lecture. All right, so let's talk about PHP arrays. Sometimes you're gonna want to store more than a single value within your variables with an array. That's exactly what you can do. So a raise allow you to store multiple values within a variable. So, for example, I think mustache is air neat. There are many kinds of mustache is and using individual variables. Aiken store each individual mustache in their own variable like so mustache. One could be handlebar mustache, too. Could be Salvador Dali and mustache. Three could be Fu Manchu, but I'd like to keep things neat and tidy and have all of my mustache is in a single variable instead of three separate variable. So for that I can use an array like so. So we start off with moustache is ah, variable. And then in the variable, we're gonna store an array. So you do that by typing out the array method array. Open with your parentheses. Make sure have closing parentheses and semicolons. So the usual way to read out your your PHP methods and there are three um, different types of mustache is here. So I have within the string handlebar separated by comma Salvador Dali, separated by comma and Fu Manchu. So I have all three of these mustache is stored in a single variable, so it's a really efficient way of storing information. So each value is automatically assigned what's called a key in the array so we can grab a specific value when we need it and we'll touch on keys later. But by default, each value has a numeric key assigned to it. So to explain that a little further handlebar has the key of one. Salvador Dali has The'keeper's of two, and Fu Manchu has the key of three. So the key is one. The value is handled are the key is to the value is Salvador Dali. The key is three, and the value is Fu Manchu. So here's the catch, though it's a little bit confusing, but the numbers actually start at zero, not one. So handlebar is actually zero rather than one so handlebar. The key is zero value is handlebar one and then to so on and so forth. So if we want to grab a value out of an array and display it on our Web page, we just have to reference the array and the key associated with the value we want to display so that I know it was a mouthful. But This is what it looks like. So in your PHP script, we're gonna use the simple echo PHP function Echo. The mustache is variable, but we can't just echo all three of them at once. It has. We have to tell PHP. Hey, I want to pull this specific value out of the array that we stored in. The mustache is variable. So in your square parentheses just reference the key of the value you want to display. So echo mustache is zero. This is going to display handlebar. Echo mustache is one this will display Salvador Dali and mustache is to this is going to display Fu Manchu. So arrays are incredibly powerful and there is a lot more to them. So what we're gonna do in this lecture is we're actually gonna jump in and start, um, putting this into practice right away. So let's check out the final example. So we have the final example. Mustache types. We have handlebars, handlebar, South Salvador Dali and Fu Manchu. It's is just a simple list, but it is not just static text were using PHP to display our array. So let's jump into our code editor and we are in a raise. And if you click on index up PHP that's going to show you the home page or the index of the lecture. We're not gonna be using that one, But feel free to check it out and see what my code is. Final is the final. The final view of the example of what we're going to make and practice up PHP is where we're gonna put that into practice. So we're gonna reference both of these right now. Okay? So at the top of your practice of PHP, Page will have your PHP script a couple PHP comments to let you know where I want you to. Teoh, organize your PHP code. So let's start with some constants we have defined. We're gonna define a constant, and the title will be a race. So let's take that out. That is the basic defined skeleton title arrays. All right, Next up, we have some custom variable. So, uh, I have the variables, my name, Unless the number this is something I'm going to just do in probably all of the following lectures just has some general housekeeping so that we can fill out what's going to be at the bottom of their Web page of the lecture, you could see the copyright 2014 Brad Iasi also up here. We have the title, and the title also displays here. So that's why we're going to be using the constants and the custom variables. So feel free to add your own custom variables here. So my name add your name and lesson number this specific one is six. Now, I don't know if you've noticed or not, but the numbers of the the lessons or the tutorials within the folders don't necessarily correlate with the actual Electra number in the entire course. So, for example, this where a No. Six air raise but the actual lecturing. Aaron, if you're viewing this from you to me or YouTube or code College, we are on lecture 12 so they're actually separate. I'm referencing the numbers here in relation to the course file. So this is number six of the course files not necessarily lecture number six in the the perspective of the entire course. So hopefully that's not too confusing. So lesson number six. And now here's where we're gonna add our mustache array. So let's do what we did in the lecture that we just learned. So let's add a variable. It's call it mustache is and in here we want to add ITER are a race. So let's ah, type out the array and the first value here. It's going to be handlebar. Let's out a 2nd 1 I believe it was Salvador Dalley, and the 3rd 1 was Food Manchu. Now you can choose any type of mustache that you would like. I've just added these three. So here's our mustache. Variable or sorry, your mustache array. And now let's just do a little bit of clean up here. So title. Let's replace this HTML comment With the constant that we set at the top of our PHP script , it's a PHP echo title that's gonna echo the title constant down here. Tutorial number, the lesson number, these PHP echo that and your page title. So that is another. That's the constant that we use. So PHP echo title. There is the constant. Now, down here in our sandbox, I want you to spit out in the HTML list the skeleton here, I want you to spit out your three different mustache is so we're gonna do that by going PHP echo, we want to echo. Our mustache is variable, but we need to get a specific value out of the array. So we do that by using square brackets and then using the key associated with the value. So zero is gonna be the 1st 1 Let's copy that. PHP scripts will have to tape it on every time. Little expert coders tip right there. Pace that outcome more times. And now just change the key. Perfect. Now, one last thing down here we have the copyright year. Ah, and now you can actually use instead of we didn't set a variable up here, but you could just straight up use PHP to spit out the year using the date function. So PHP date parentheses and in date, we want to specify why for the year, the full year, in my case, 2014 if you're from the future. Hello And my name. So we have the variable. My name a player. PHP. Let's echo. Save that. Now, remember, this is the most important part of the lecture. These were just kind of little snippets. Some examples that you would use PHP in the rial coding world. And here is you. Ah, you're trying to use PHP to echo your race. I'll check it out. Go to your practice of PHP page. And if you did it right, you should see your three mustache types right there handlebar, Salvador Dali and the Fu Manchu. And looks like down here something's not right for me. Copyright. I wonder what that IHS. Let's go back to her code. Here's a mistake. I forgot to use Echo. Now save that. Check it out. Boom, Fix. All right, so hopefully that wasn't too hard. If it was a little difficult or too fast, feel free to go right back to the beginning or hit the pause button. And before we move on, I have a quick favor to ask you. I've dedicated thousands of hours to creating great content for my students. And the reason I can reach so many people at this point is because of people like you. This course alone has taken me months to create, and I'm not asking you to pay anything for it. All I ask of you is one little thing. If you're checking out my course from YouTube, I would love if you could share this course with your friends, family and work colleagues. And if you're checking this course so from you to me, I would especially appreciate if you could give me a quick rating and review using the star rating and the review box. You can leave me an honest review, and you can always change it later. Should you have a different opinion? By the end of the course, you're awesome. Scene the next video. 13. Associative arrays: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called associative arrays. And in this lecture, we're gonna be continuing from where we left off in our previous lecture about PHP arrays. And we're gonna dig in a little bit further and continue with what's called associative arrays. So let's jump right in in your code Dynamic websites course files. We are in 07 associative arrays. Open up your code editor and opened the final and practice PHP files of 07 associative race . So here's the final file and the practice file. What? We're working on our associate of race right here. So I want to show you the final example of what we're gonna be building with associative race. We have a string of text here that's talking about a specific mustache and there's a couple things in here you could see in bold that we're gonna be using PHP associative arrays to display that text. So let's go back to the lecture and let's dive into associative race. So remember how PHP automatically assigns a number to each item in an array. So 01 and two while using associative arrays. You can give a custom name to the key rather than using a number. So it looks like this. Here's your variable and an array. But instead of all in one line, we split it out. Here we have name. So this is replacing the default key of zero. So we have name and then we assign the value to the key by using this the equal sign and the greater than sign and on the right, we have the value. In this case, we're using this string and that assigns the key of name the value of handlebar within array. So we comma, separate the items. The next one. We have creep factor. So this is replacing the key of one. And then we assigned the value high comma separate the next item Average growth days is the third key, which would by default, be too. And then we assigned the value of 14. And then we close the array with the parentheses and the semi colon. So now let's say I wanted to display specific information from the array. So if I wanted to pull out a specific item from that array, I would do so by simply referring to accustom key in there, Ray like this. So here's your PHP script. We're using the echo handlebar, the variable and then in in the square brackets. Instead of referencing the number, we're referencing this specific key in the array, so creep factor. So that will echo the creep factor of our handlebar array so it would echo Hi. So let's go back to our final example here and you could see the handlebar mustache. This mustache is quite the dirt squirrel. It boasts the creep factor of high and takes 14 days to grow on average. So let's check out your example. It's just gonna be the same thing, but without the values, the dynamic values in the array. So let's go to our code editor. Open up. Practice that page, Pete. And let's use some PHP associative arrays to do what we just did or what I displayed in the final example. So some basic clean up as usual, let's add, are constants, variables and all that sort of stuff. So we're gonna define the title again. And in this one, the title is associative race custom variables. I'm just copying and pasting for speed sake. You can do the same. But if you want a hand code the mount, that might be better for you as a learning experience, because then you'll get used to typing out variables and constants so on and so forth. So we have my name. You can add your name lesson number. This one is seven within the context of our course files. Now here's the good stuff, the mustache associative array. So let's go ahead and add that handlebar is going to be our variable. And let's add the associative rate so array. But let's split these up. So in between here, just hit, return or enter. I'm just gonna tab this in so it looks a little bit more clean. And in between here, let's add our array item. So the first item will be obviously a key, and that key is name. So the name of this handle of this variable or array will be handlebar. Second line. Let's add another item in our associative array, and that will be creep factor. And remember, these are all custom. This could be named whatever you want them to be. Great factor will be high on the third line the next item will be average growth days and that I'm just going to say 14 and you don't need to put a comma at the end of this one unless there's another item following, so you can leave it like this. But I like tabbing these out a little bit, so they all have. They'll look, It's all pretty clean. You can see the key here, separated in the center. Ah, and then the value on the right side. You don't have to do that, but it's just it's easy to read. So there is our mustache associative ray. Let's go ahead and save that. And now let's just do the basic housekeeping stuff. So we're gonna add the PHP page title. We're in a echo, our constant gonna coffee that because we do it a second time right here. The lesson number PHP echo lesson number and we go down here. We have the year because we haven't defined at the top in our PHP script. Ah, variable. With the here, we're just going to use the date method in PHP, Echo date and in dates. We want to call the actual year and then your name. Here we go. PHP, Echo and My Underscore name. See that you'll have all those things. Those things should show up now in your practice page. So have the page title right here and then the copyright information stuff. But we don't have this stuff yet, so let's go ahead and show that good stuff. So the mustache name. So we need to get the mustache name out of our handlebar associative array. So how do we do that? PHP. We're in a echo handlebar, so the handlebar variable. But we can't just do it like this because it's an array and it's not going to show something. So let's let's see what this does. Save it and check it out. The array mustache. It's just an array, so it's It can't. It's just showing what the thing is. It's not actually giving us any useful information. So to pull that information over the array we need are square brackets here and then referenced the key. So name. Save that and check it out. The handlebar moustache perfect. So let's go in here and there should be another H Mel flag here that we can fill in. So the creep factor we wanna echo are creep factor, so again, handlebar. But we need to use our key creep factor that will give us our creep factor. Let's check it out. It boasts a creep factor of high. There it is and takes. We need to add the growth days now, so PHP echo the handlebar average growth days. Semi colon say that. Let's check it out. Looks like it's there, but we just need a space in between there. So let's just give us the space after this PHP script, Save it, check it out. There we go creep factor of high and takes 14 days to grow on average. So there we go. It's to a quick little review, we added, are constants and variables. Pretty straightforward. We should know that stuff pretty good by now. Here's the new thing. We're learning associative arrays, so we have our variable. We're gonna add in array. But it's an associate of a rate because we are adding multiple items with custom keys rather than the default. Um, numbers. So we have the name creep factor. An average growth days. We added those here. This is how you you spit out some some valuable information from the associative ray echo the variable in square brackets. We reference the key, and that should be it for our super basic lesson on associative arrays. Stay tuned because we are not done yet with a raise up. Next, we are going to be diving even further into this stuff and what will be called multi dimensional arrays. Now we're getting really into the good stuff, so we'll see. They're my friends. 14. Multi-dimensional arrays: Hey, everybody, welcome back to code dynamic Websites of PHP. This lecture is called multi dimensional arrays and in this video we're going to continue from where we left off in our previous lectures, where we were learning about PHP arrays and PHP associative arrays respectively. This lecture is a little bit more advanced, so hold on tight and here we go. In your code dynamic websites course files were in 08 multi dimensional raise. If you go to your browser in less than eight multi dimensional raise, I'm gonna show you what we are going to be building. So the final example we have three descriptive text sections here with three different mustache is and separate explanations of each of the mustache is and we're gonna be using PHP multi dimensional raise to build this. So let's go back to the lecture and jump right in. So this is where we start getting a little bit crazy. We can harness the true potential of a raise by using multi dimensional arrays, which is simply an array that is comprised of multiple race. So a raise within a raise. So this is what it looks like. We have our mustache is variable, and we start off with the array function. But inside the array, instead of just having your typical key and value combination, we have another array, and inside that array we have our key and value combination. And then we comma, separate. The arrays do the same. We have three of them, and then we end our original array. So we have a whole lack of information inside a single variable, which is pretty awesome. So you're probably wondering how the heck we display this info on our screen? Well, we first have to reference the parent array. Mustache is then the numerical value of the child array. So handlebar is zero. Salvador Dali is one, and Fu Manchu is too. So this array is zero one, and to and finally the custom key of the information we want to display. So name creep factor, etcetera. So it looks like this. It's a little bit easier when you see it, so Ph B. Echo mustache is variable. They were referencing the numerical value of the child array. So let's say to and so that will be 012 So will be the Fu Manchu and then the name. So the above code, the PHP script right here will display Fu Manchu because we're echoing the mustache is variable. We're calling the second numerical value. So 01 and two were calling this array and then the name within that array. So that is how you display Fu Manchu within this. So let's go into our code editor and actually build our final example. So in your code editor, open up, final and practiced up each be in euro eight month, multi dimensional race. And let's start off by doing the little housekeeping we have in each of our PHP. Files we have are constants. So we're gonna call this one title multi dimensional race, our custom variables. We have my name, so put your name and the lesson number. And in this case, in the context of our course files is Lesson number eight now toe work on our mustache, multi dimensional array. So let's start off nice and simple. Mustache is, let's add our ray function. Great, nice and simple. So now let's do a little bit more here, Enter a couple times, let's clean this array up a little bit. And inside this array we're gonna add from space and add another array. Atacama. After that array, paste it twice. So basically, this is the skeleton of a multi dimensional array. But of course we have to add the information within our Children. Elements here are Children arrays. So the 1st 1 we're going to start off by adding a combination of key and value pairs. So in here we're going to start with name, and that will be the handlebar. After that, we are going to add the creep factor. And that was high. And the last one will be the average growth days, and we'll say 14. So within our next to raise. Basically, let's just copy this what we've just wrote and ah, let's some add it in here twice, cause then we could just change the values of each of them because they're fairly similar. So the 2nd 1 is thesis Alva Door Dolly and the creep factor is extreme. Average growth days. Let's say 62 the last one is our Fu Manchu. The creep factor will be very high and the average growth days 58 so save that there is our month multi dimensional array and Now let's just go through an ad, replace the page titles, lesson numbers and so on, so forth. I like doing this because it's a good way for you to get into practice of, of using PHP to make your website a little bit more dynamic. And because constants and variables air still fairly new concepts to you, it would be good to just use them a lot, so they just become totally normal to you. So what's Echo our page title here? Gonna copy that? Because we're gonna use it one more time down here in the page title section. In between the small tags and the lesson number, we have that PHP echo lesson numb, then the down at the bottom. We have our copyright info, so we have the year. So let's use a PHP date function. And let's call the year the full year and now your name or news PHP to echo your name. That would be the variable. My name Great. So now let's go into our sandbox here. Now that we've got that other stuff out of the way here, you can see I have a couple HTML flags or three smell flags where I want you to replace with some PHP using the multi dimensional array than I have in HTML. Comment that says repeat above a two times. So basically it's exact same thing pasted out two more times for a total of three times, and each of them has a separate mustache with their information, So the 1st 1 will be our handlebar. So PHP we're going to echo our mustache is variable. But because it's a multidimensional array, we need to call the numeric value off the A raid, the child array and then the key for the value we want inside the child array. So I know that's a mouthful, but basically this is how we're gonna do it. If you remember to square braces, brackets, the 1st 1 will be the value, the numeric value of the child element. So the 1st 1 handle our is zero, remember, starts with zero, not one, and then we want to access the name of that array, so that should get us handlebar. Let's check it out. Handlebar mustache. Great. We did it. Let's go back. This mustache is quite the dirt squirrel. It boasts a creep factor of HTML comment. Let's replace that with the creep factor. PHP. We're gonna echo our handlebar. Sorry. Mustache is variable. And in our square brackets, we are going to say zero and creep factor. So that is going to grab the first child array because of zero and then creep factor within it. And then now, growth days Replace that PHP echo. You know, the drill mustache is square brackets, and we're gonna reference zero for the first child array and average growth days. Cool. Save that. Let's see if it worked. The head of your moustache is quite the dirt squirrel. It boasts a creep factor of high and takes 14 days to grow on average. Perfect. If yours looks like that, you nailed it. So now all we gotta dio is copy and paste this thing two more times. And in it, we just literally have to change the numeric value of the array. So let's say the 1st 1 this is gonna be the 2nd 1 So this will be Salvador Dali. Change it here as well. Here we go. And right here That should change the 2nd 1 to Salvador Dali moustache, with its respective information within the array. And now the 3rd 1 remember, is thes is number two. And then we replaced the zeros with the to save that. Check it out. The Salvador Dali moustache is quite the dirt squirrel votes the creep factor of extreme and take 62 days grow on average to Manchu creep factor A very high and takes 58 days grow on average. Awesome! If yours looks like this, you nailed it. Now I just noticed one small little thing. My copyright is wrong at the bottom. You need to echo the date. My bad. Check it out. Perfect. All right, So if you made it this far and your moustache is look fantastic, then good job and hold on tight because we have one more lecture using all of the arrays that we've learned so far, So I'll see you there. 15. Get your hands dirty II: Hey, everybody, welcome back to code dynamic websites of PHP. This lecture is called Get your hands dirty And in this video we're going to put together a little something with everything we've learned so far about PHP arrays in your code dynamic websites course files we are in ona and get your hands dirty. Let's have a look at the browser to see what we're building. We have three chunks of text here in the sandbox, and each of them has something about a person from some country and some info about their mustache. Each of the bold pieces of text were using PHP arrays to generate. So let's jump right in. Go to your code editor in Ono and get your hands dirty. Open index and practice Practice is where you're gonna be building your version of this little site and index is the final version of it end Also reference if you want to use that , So let's start by doing a little clean up. We need to define our constant and that would be title and this one will be a raise. It's called a raise because here in the title tank, we already have get your hands dirty. We need to replace title with the Ah, sorry. We need to replace Title with the title Constant, if that makes sense. So let's echo the title. Perfect. I'm gonna copy that in pace that one more time down here in between the small tags Good to go Variables. We only have one simple one and that will be my name And add my name there, and we're gonna use that down here in your name. But first, let's replace year with PHP year. Remember to echo date year and replace the your name html Comment literally with the My name Variable. Great. We should be good to go. So let's jump right in to start building our arrays First, we're going to start with our basic Array age group. Remember, this is the basic skeleton of an array, and we have some items in here. This one is child comma, separate each of them teenager and the last one will be adult. Great. So there is our basic PHP array. The next set of a raise will be the associative arrays. So let's start by doing our trusty handlebar mustache. Clean this up a little bit and in here we're gonna use the key name and the name is handlebar. And then color color of this one will be black. I'm going to copy this and pace it because I don't wanna have to write it again. Unless you really want to be good for muscle memory. Get your fingers used to writing a raise. It's good to do that. Fu Manchu is the next one, and the name will be Flu Manchu, and the color will make it brown. And let's add another. And this one will be the Salvador Valley. And the name obviously is Salvador Valley, and the color will be blonde. Perfect. Next set of a raise or the next array will be multi dimensional arrays. So let's add our gentlemen variable array, nice and simple. Here's where we started getting a little messy in here. We need to add three different a race comma. Separate the erase. The last one does not need to call a comma. Okay. First name this is we're gonna be adding our gentlemen. So the first name will be Carter and his country will be my home country of Canada array. The 2nd 1 we're gonna Add another gentleman. And that will be Rhodri go from country. I have not been to yet, but I would love to go. Uruguay Shadow tell you people from Uruguay or as us Canadians say Uruguay. All right, first name the sky is Giovanni from you guessed it. Italy! All right, cool. So there is our multi dimensional array. This is our associative array and the basic PHP array. Now let's put those into use down here in the sandboxes where we're gonna be adding each of the gentleman in the H three tags and the description about them. So we're starting off with the 1st 1 And that will look like Carter from Canada. Carter's quite the adult. He sports a solid handlebar mustache that is black in color. So let's add that one. All right, in the H three tag, we need toe echo. Our, um Carter, we need to echo Carter's name from our multi dimensional array. So this is how we do that? Let's reference are gentlemen variable. We need to reference the number the index of the array within the multi dimensional rain. So the 1st 1 has index of zero, So that will be zero. Now that we're referencing Carter's array, we need to get his first name. There's Carter. All right, so that should say, Carter, let's check it out. Carter. Perfect. We're not done yet, though. Carter from We need toe get his country. So, echo, gentlemen, happens to be zero still and country nice and simple. So, Carter, from Canda Now we're in the paragraph tag. Let's echo his name. We've already done it up here, so I don't want to rewrite this out again. Carter is quite the PHP echo. Here is ah, here. The age group. So we're gonna choose one of these age groups. He's an adult. So we need to echo Age Group. And, ah, we're referencing the last one, which is the third in which has the index of 2012 All right, so that would be too. Carter is quite the adult exclamation point. He sports a solid and he has a handlebar, So PHP echo and let's reference handlebar. That would be me perfect handlebar name. That should be good. Check it out. See what looks like so far, Carter's quite the adult. He sports a solid handlebar. So let's write mustache after that, that is what color is it? PHP, echo, handlebar and the color we want. There we go in color, so try and wrap your head around. This looks a little messy, but that's OK. It's good for practice. Let's save it and check it out. Carter is quite the adult. He sports a solid handlebar mustache that is black in color. Perfect. So what's great about this? Next? These next two just left a copy and paste and just replace the PHP um, a raise and the indexes and the references. So quite simple. Copy paste. So the next one, we're gonna go, Gentlemen, One first name from gentlemen One country and then, gentlemen, one first name is quite the teenager. Where is the teenager? At a 01 So that will be index of when for age group. And he sports Fu Manchu. So this will have to change this to Fu Manchu name. That's good. That is what color this would be Fu Manchu again. Color. So let's check that out or older. Ego from Uruguay is quite the teenager. He sports a solid Fu Manchu mustache that is brown in color. So great, it's ah it's perfect, but the only thing different is actually have different texts. Here is there as a rather dapper teenager he probably wears that is colored in a gentle So let's, let's fix that. So Rodrigue Oh, is who is one of it is a rather dapper teenager. He proudly wears a Fu Manchu mustache that is colored a gentle and let's remove in color at the end. So let's have a little look at that. Rodrigo is a rather dapper teenager. He proudly wears a Fu Manchu mustache that is colored a gentle brown. That's beautiful. All right. Next one, we have Giovanni from Italy. Let's copy and paste again and replace what we need to replace gentlemen too, Gentlemen to so first name and country gentleman to first name is a rather dapper Giovanni is a child, so that would be zero rather Dartford age group zero. There we go proudly wears a This guy has a Salvador Dali, and we're gonna change what the text says. So let's see. Giovanni might seem too young for a stash because he is a child, but he proudly displays his Salvador Dali moustache at school. Although it's a little hard to see because it's light brown. Let's check it out. See, what would that turn into? Your body might seem too young for a stash because he is a child, but he proudly displays his Salvador Dali moustache at school, although it's a little hard to see because it's light Blonde perfect. All right, so here's a little review at the top. Here we did are constants and variables, but the meat of this lecture was theory Azour, basic array, our associative arrays and our multi dimensional array. And we put them into practical use down here in our sandbox, where we talked about three divers, gentleman with very different mustache is in very different age groups. So if that was little fast, no problem. It's good thing you're watching a video. Just rewind. If that's what it's called nowadays, back to the part where we started coding our PHP. Follow along Copy and Paste. Do it over and over again until you have a good idea of how this works, because trust me, it's gonna be really useful throughout the rest of the lecture and throughout the rest of your coding career, so hopefully that was helpful, and I'll see you in the next lecture 16. If statements: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called if statements and in this video we're going to be diving into a totally new concept with PHP, and I think it's gonna be very exciting. So here we go in your code Dynamic Websites Course files folder. We are in 10. If statements go ahead and open up your code editor and open final that PHP and practiced up PHP in the 10. If statements folder final dot PHP is the final example, we're gonna be building and practice. A PHP is where you can utilize the sandbox to build the final example, which looks like this. Yep, 20 is certainly less than 50. It's just a string of text, and it doesn't look too impressive, but it's what happens behind the scenes. That's really cool, so we'll get there. Let's jump in to the lecture. The point of coding in PHP is to make your website dynamic or smart so that it can make logical decisions. What I mean by this is your website can make decisions on what to do next, based on user input, user conditions or parameters you've set yourself here are some examples. When a user logs into their account, they must type both their user name and password. What what if their password is wrong? What if they didn't type valid email address? What if they forgot to take their email address altogether? PHP can handle what to do in these situations, using, if else and else if statements. What about if a customer tries to buy a product online? But what if that product is sold out? PHP can let the user know the product is sold out because you can program it to calculate how many items of that product are remaining pretty cool. What if a user uploads an image that is too large? Ball PHP can compare the uploaded image with your parameters and tell the user to upload a smaller image size if it exceeds the limit that you've set and much more. So let's start with the simple if statement, it works something like this. If this, then that. Okay, I know that was a little bag, but let's expand on it just a bit, So if expression is true, then do something. If expression is false, then don't do anything. What's an expression, you're probably wondering what an expression is. Well, here's how PHP dot net explains what an expression is. Expressions are the most important building stones of PHP in PHP. Almost anything you write is an expression. The simplest yet most accurate way to define an expression is anything that has a value. The most basic forms of expressions are constants and variables. When you type variable A equals five, you're assigning five into variable. A five obviously has the value. Five. Or, in other words, five is an expression with the value of five. In this case, five is an integer constant, so hopefully that made sense. But basically all you need to know is an expression is anything that has a value. So let's jump back into if statements. So let's see what they actually look like in PHP now that we know the syntax. So if expression and then in your curly brackets the code to execute if the expression evaluates to true. So if we expand in that further, it looks a little more like this, so we'll set some variables. We have a equals 20 and B equals 50. Now, if a is less than B, which is obviously true because 20 is less than 50. So this will evaluate to true, and it will echo this statement. Yep, A is currently less than be, but because we're using PHP, it won't say a. It will actually say the value of that variable. So 20 is certainly less than 50. So, as you can see, we are using the less than symbol to check if the variable A is smaller than the variable B . If the expression is true than pH, people echoed the text. Yep, 20 is certainly less than 50 and if it's false, it just dies. Nothing happens now. Wolf jump into a little later in the next lecture. What happens if something is false? But for now, let's leave it like this if statements could be incredibly powerful. But these are just some very basic examples to get you started. So why don't we jump in and actually try out your first if statement? All right, so when you're practiced up, PHP file in your code Editor under 10. If statements, let's do our housekeeping. There are things that we regularly do at the beginning of our lectures, and let's define our constant for the title and the title in this one is if statements and then our custom variable So that would be my name. And you will put your name and the lesson number in the context of our folder. So 10 in the case of this one, all right. And we're gonna have to set a couple simple variables here. We're gonna do a which equals 20 and B, which equals 50. And now let's just add our title here using our PHP echo function and echo the constant. And then we're also going to echo that same title. So just copy that PHP scripts and pasted between the small tags and then the lesson number that we defined in our variable PHP echo lesson numb and then down at the bottom. We have the year we're gonna use our PHP echo date year and then our name variable will echo right here. PHP echo my name. So let's jump into our sandbox here and do our first PHP if statement So start your PHP scripts. And in between there, right? If so, here's the skeleton of an if statement if and then you're parentheses, curly brackets and in here. We're gonna add our expression. And that will be if a is less than be. And then if it evaluates to true, let's do something in between our if statement in the curly brackets echo. Yep, A. The variable A is certainly less than be. And then we'll end that with semi colon. Save that. Now let's check out your example in practice up. PHP. Yep, 20 is certainly less than 50 you might be wondering. Well, that's just that's there just because I wrote Echo like I don't see the if statement working Well, if you want to see that the if statement is actually working, why don't you change the values of the variable to see what happens? So let's make a 200 so a is no longer less than be. Let's see what happens. Nothing. Nothing's there. The if statement just dies because A is not less than B in this case. So let's put the back to 20. Check it out again. There it is. 20 is certainly less than 50. So that's it for our if statement lecture. We're going to keep going in the next one and dive into else statements which you tagged onto the end of your if statement. If this is true, then do something else. Meaning if it's false, then do something else. So we're gonna jump into that in the next electoral See there. 17. Else: Ola Toto's Bienvenido are called dynamic websites with PHP. And my name is Brad. This lecture is called else What? So in this lecture, we're gonna be continuing from where we left off in our previous lecture, which was PHP if statements so open up your code. Dynamic Websites course files folder. We are in 11 else in your code editor, open the practice and final dot PHP files under your else folder. The practice is where you're gonna be building the final example and final dot PHP is thief final example itself that you can use for reference. Here is what the final example looks like. Boom. So you like oranges? Very impressive PHP script we've got going on here. I know it looks a little small and silly, but we're actually using PHP if end else to get this result. So let's jump into our lecture to find out what's happening here. So we figured out how to execute some code if an expression evaluates to true. But what about when the expression evaluates to false Often you want to execute some code if a certain condition has not been met. So this is where else comes into play Look at else as an extension of the if statement, this Intacs looks like this. If expression is true code to execute, if true else code to execute if false. Now let's take a look at a real world example. So when our PHP script we've got our variable faith, fruit equals orange. If faith fruit is equal to pineapple echo yea, pineapple is the best because it is else is where we're using the else echo. So you like oranges. So basically we're checking to see Hey, is your favorite fruit pineapple? If it is, then you're awesome. You're on the pineapple team. Otherwise you probably like oranges, which is disappointing unless there Florida oranges. Those air. Very good. Now wait a minute. You probably noticed something a little funny here in our if statement, we have this double equal sign. That was not a typo. That was very intentional. So let's explain why not all equals are created equal. It's good to remember that the double equal sign is different than the single equal sign. The former means is equal to while the latter a signs of value to a variable. So, for example, if I were to write in PHP if favor fruit, and then the single equal sign pineapple. This will always evaluate to True, because the single equals symbol assigns the value into the variable rather than comparing it. So the double actually compares the variable to the value on the other side of the symbol. Where is the single equals sign actually assigns the value to the variable. So here's Here's it in in practice the single equals symbol for assigning orange to favor fruit, whereas here were comparing favor fruit or the value of faith fruit, which is orange to pineapple. So if they've fruit is equal to pineapple rather than they've fruit equals pineapple, because then we're just gonna be replacing the value of the variable with pineapple rather than orange. So we will always evaluate to True. So keep in mind, single equals is not equal to double equals. Hopefully, that made sense, all right, so let's jump into her code editor and start doing some code. So in your practice stop PHP file, let's add are constants and variables. Everything we've been doing so far, this won the title is else, and we're gonna add our custom variables that will be your name and the lesson number, which is 11 in the context of our quote dynamic websites course files. Now the one important variable that we're gonna be doing here is thief Favor fruit variable . It's a fait fruit orange cool. So let's add are constants and all that sort of good stuff here, like we've been doing. This should be like a cakewalk for you now writing our title on a copy that do the same old same old pasted in here. We have our lesson number. Let's add that variable echo lesson number you can see here in Kota to it recognizes that I've already defined that variable, so it gives me a little quick, um, shortcut to be able to just hit, enter and add that variable because it's already been defined. So if you're using coda to pretty cool helps you speed up your coding year. Let's add our year PH B Echo date, the year and our name used the PHP echo my name Variable. We're good to go there now We're going to start doing are if and else statements right here in our sandbox. So in there, add your PHP script and then start with an if statement there is the skeleton. Now compare thieve fruit to pineapple. All right, so in here, we're gonna echo something. If this statement happens to be true and will say, Yea, pineapple is the best. Like I said, because it is the best else this is we're using else right after the if statement after these, the the closing curly bracket ad else and then open and close your curly brackets again in there were gonna be adding our, uh what happens if it is false? Echo. So you like oranges? All right, so save that and check out the practice at PHP file. Final example. Check with your example. So you like oranges, so that's it. So feel free now to just change the variable here or what you're comparing it to. Maybe even let's say your favorite fruit is pineapple, which is my favorite fruit. So now if I say that, let's see what happens. Yea, pineapple is the best. See? Pretty cool. So that is the else statement. You tag it onto the end of your statement, and then you have an even better knowledge of how to use PHP if and else is super powerful . So I'll see in the next lecture 18. Else if: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called else if and in this lecture we're going to continue from where we left off in the previous lecture, which was, if statements and we're gonna learn a little bit how to extend our if statement using the else if statement. All right, So when your code dynamic Websites course files folder, we are in 12 else. If in your code editor, make sure that you open the final and practice a PHP files in the 12 else. If Fuller the practice that PHP file is a basic skeleton that I've set up for you so that you can create what I've already built in the final dot PHP example show you what that looks like right now. It says, allow state Abla spaniel and I know it's just a simple Spanish sentence, but we're actually using some PHP programming, using, if else if and else to achieve this result. So let's jump into the lecture and then we will get our hands dirty with some code. So there is one last piece to the if an else puzzle, it is called else. If pronounced else if else. It is a kind of combination of if and else PHP dot net puts it quite nicely. Like else. It extends an if statement to execute a different statement in case the original if expression evaluates to false. However, unlike else, it will execute that alternative expression only if the else if conditional expression evaluates to true. So if the above explanation is as clear as mud, the syntax looks just like this. If expression code to execute, if the above expression is true else, if different expression code to execute if the first expression is false, but the else if expression is true else. Coat execute If neither of the above expressions are true, so now if we added some real PHP, it would look a little bit like this. So PHP we have need of language. Variable Spanish if need of language is equal to French. Then echo boo boo par Les Francais else. If native language is equal to Spanish echo, Ola will start last manual else Echo. Hello, you probably speak English. So here's the commented code, just with a little bit more of an explanation. So we set a variable. You should know how this works by now. Now the first if statement right here. If the native language is French than echo some French else. If the need of language is Spanish, then echo some Spanish else. The native language is neither of the above, then just echo some English. So basically in plain English, this is if the native language variable or your native language is French, then echo French. Otherwise check to see if their native language is Spanish, then echoes in Spanish. Otherwise, if they're if they don't speak French or Spanish than just echo some English because hopefully they speak it. All right, so let's jump into her code editor. Let's start off by adding are constants and variables. So the first constant is the title, and it is else if and then we're gonna add our custom variables, and that will be my name and lesson number. Unless the number is 12. In the context of this folder, remember that it is not the lesson number in the entire course, because we're much further along, but just a reference to where we are in the code Dynamic Websites Course files folder one more very well. We need to add native language. And although it is not my native language, I'm just going to put Spanish for the purpose of this lecture. So let's start out by adding our titles and such peach be eco title. Copy that. We're gonna do that between this small tag down here. We're gonna add the lesson number using PHP echo lesson number. And down here we have the years of PHP Echo date capital. Why gives you the full year and then the name using PHP Echo, Echo. My name. Variable. There we go. Good to go. Now let's jump into our sandbox. Start your PHP script and let's start by adding, Ah, basic PHP if else if and else skeleton looks like this All right, so there's the basic skeleton and let's start adding our first expression in the first if statement. So, if native language is equal to French, then echo bones you who parley? Oh, see? All right, so now because I use this little funky letter here, I'm gonna encode the entities. And if you're using quota to you can easily do that here. Otherwise, you just have to use the html special html character ampersand C c E v i l and semicolon that will get you that character. Okay, now in the else if organise, ask or check if the need of language is Spanish and then we're gonna echo Mullah upside down. Exclamation point was stared. I will, uh, spend your and right here we have some special characters. So I'm going to highlight this with Coda to right click and then processing in code entities that will get me my ups upside down exclamation or inverted exclamation points. So ampersand I e x c l semi colon who stayed Abla Espanol So we have the end with the little till the thing on top. So m percent and t i l d books percent n t I l d e semicolon will get you the end with the tilting on top for a spaniel else we're gonna echo some English. Hello? You probably speak English, all right. And that with the semi colon, make sure to have these lines also end of semi colons. I almost forgot that and say that Now go to your co. Ah, your browser and check out your example. All right, here it is. Ola Starla Espanol. So Now let's see if we could change this result, and all we need to do is change the value of our native language variable. So let's just say your native language is French Boo boo par les Francais. And let's just say something else like German. Hello, you probably speaking English. So it's We don't have our little script here to be smart enough to know if we speak German or if we speak something else, like Arabic. It just says Hello. You probably speak English because our program here in PHP on Lee checks to see if we speak French or Spanish. If you wanted to expand on that, however, you can add multiple else if statements. So let's just add one more here else. If remember to add your expression. Now, let's say maybe you speak a different native language. Let's say your native language is Arabic, since we just used it up there. Now I don't know how to write any air back, unfortunately, but let's just say in English here a you can speak and awesome language Arabic. All right, so now save that and make sure your native language were able to set to Arabic and check it out. Yeah, you could speak in awesome language Arabic. Cool. So that's how you do the else If statement and remember, you can add multiple here and we added an extra one he earned between the last else if in the end, the else. And we just added another instance here to make our PHP script even smarter. So hopefully it shows you the power of the PHP else and else if statements when they're tagged onto the end of the if statement and hope you enjoy the lecture, I'll see in the next one. 19. Get your hands dirty III: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called Get your hands dirty A. And in this video, we're going to be creating a little mini PHP program that we're going to put together using everything we've learned so far in this if else else if section we've been covering So let's jump right in in your code. Dynamic Websites course files folder. We are in 13. Get your hands dirty. Open up your code, editor. Make sure to open the index on and practiced up. PHP files in the 13. Get your hands Dirty folder. Practice that PHP is where we're gonna be building what is in the index dot PHP. Final example. The final example looks a little something like this. Get your hands dirty. If Elson else if in our sandbox here we have welcome human, please leave the black Rhino alone. Another example. Congratulations for being on Earth for more than 20 years and a combination. Well, then you do not speak German. Nor are you a rhino. So this speech be script is quite the doozy. And I think we should jump right into the code so that you can see how I am building this, and you can rest assured, I am actually using, if else and else if to create this funky little example. So let's jump into our practice that PHP file. Start off by adding your constant, which will be the title if Elson else if and one custom variable, which will be my name. Well, one regular custom variable, which is my name. We're not going to do the lesson number like we've usually done because this one's just called Get your hands dirty. All right, so let's just add those things to get them out of the way. PHP Echo title. Copy it and paste it in between the small tags and then at the bottom. We have our year. PHP echo, DEET, capital Why and our name PHP Echo my name. Perfect. All right, great. So now let's add a few more custom variables, and we're going to use these variables for our if else. If an elf species is one of them. And let's say human, let's add another one called native language, and you might notice here that I used camel caps and or or camel case, as it's also called Basically, instead of using an underscore like I did in the previous lecture, I kept it all together without a underscore, and I put a capital l. So it kind of has that camel hump so native language, so you can see that it's two words. It's kind of, Ah, programming convention that you can use, And I think I'll try it here just to expose you to a new way of writing your code. So native language English. And let's add another one years on earth again Camel case. And let's just say 25 you could put whatever age you want or number of years you want. But let's start with 25 and then now down in our sandbox is at our PHP script, and in between there, let's add the if else, if end else skeleton, if else if and else perfect. So let's start with the first expression. We're going to say species is equal to black rhino, So if species is equal to Black Rhino, then we will echo a paragraph tag because you can echo HTML in between our strings there and let's say, Welcome Black Rhino, You and the rest of the rhinos will love this big lake. Perfect. All right, our second expression in the else if statement let's say species is equal to human. So if this else if the species is equal to human, let's echo another paragraph tag. And in between the paragraph tags will say Welcome, human, Please leave the black Rhino alone. Perfect else meaning if the species is not a black rhino or a human echo Another paragraph tag and in the paragraph tag just right. Welcome to Earth. You're kind is unknown to us. Awesome. So let's see what that does. Let's go to our browser and go to check out your example so you can see that the text spits out Welcome, human, Please leave the black Rhino alone on the reason why is because here in our PHP script, we're checking to see if the species is equal to black rhino or human. Otherwise, echo this and because the species matched the human, then we're spitting out this text. Welcome, human. Please leave the black rhino alone. But what happens if we change the species to black Rhino? I think you know at this point let's check it out in our browser Welcome, Black Rhino. You and the rest of the rhinos will love this big lake. Cool. What if we changed to something that doesn't meet or match either of those if and else if statements something like donkey? That's refreshing. Check it out. Welcome to Earth. Your kind is unknown to us. Obviously our script doesn't know what a donkey is. It just assumes if you're not a black rhino or a human, you're obviously an alien. So in this case, the donkey is an alien. If we added an extra else, if statement that said species is equal to Donkey, then we can have a different echo statement here. But right now it's just defaulting to the else because it doesn't match black rhino or human. So I'm gonna change that back there. Now let's move down below her PHP script and add just an H five tag and say another example . And after that, we're gonna add another PHP script. And in between there, let's add our if else if and else skeleton the first expression in the F statement. Let's check to see if years on Earth is exactly equal to 20 and if so, echo Congratulations for being on Earth for 20 years and with a semi colon. Remember that else? If let's check to see if years on Earth is less than 20. If so, echo not quite 20 yet young grass hopper groups okay, and else if it doesn't match either those statements echo. You must be more than 20 years old, so let's check that out and see what it looks like. Another example. You must be more than 20 years old. And in fact, that is true because in our variable years on Earth, we said 25. What if we said 20? Let's check it out. Congratulations for being on Earth for 20 years. What if he chose a large number like 94? You must be more than 20 years old. So what if we said I don't know? 10. Not quite 20 yet. Young grasshopper. Cool. So this works quite well. Let's move on and add one more example. So below are PHP script there. Let's add H five tag that says a combination. So a combination of both PHP script in there again if else if and else the first expression we're going to say native language is equal to German. If your native language is equal to German Echo Beer Co men all right else. If your species is equal to Black Rhino, then echo. Oh, you must be a rhino else. If it doesn't match either of those echo. Well, then you do not speak German. Nor are you a rhino. Excellent. Save that and let's check it out. Combination. Well, then you do not speak German. Nor are you a rhino. So why don't we change some variables up here and see what happens? What if we set our native language was German? What happens now? Bill, come in. What if we said our species was black Rhino? What happens then? Well, you could see that this changes to welcome Black Rhino. But down here, this stays the same. Because are if and else if statement checks first to see if the native language to see if our native language is German. If that fails and it goes on to the LCF. But because this past is true, then it's going to echo this first statement. So what if we said our language was French but we were still a black rhino, French black rhino Oh, you must be a rhino. So you see how that works. And then the else we already had that So we checked to see for a German. Great. We check to see if we were a rhino that didn't speak German. It echoed this. And we checked by not having our native language be German or have our species by species be black rhino. So that echoed the well done. You do not speak German, nor are you a rhino. So quick little review. We added our three variables here, which we played around with down here in our sandbox, where we did a series of, if else if and else, um, statements to see if our species to see the years on earth and to do a combination of those by checking our native language and er species. So hopefully that made sense. And that was fun. And that got you a little bit more excited because we're gonna be diving a little bit deeper into PHP in our next series of lectures, and we're gonna start with comparison operators. What the heck is that? See there 20. Comparison operators: Hey, already welcome back to code dynamic websites with PHP. This lecture is called comparison operators and in this video, we're going to be diving a little deeper into something we've been kind of playing around with for the past few lectures. So let's jump right in in your code Dynamic Websites course files folder We are N 14 comparison operators. Open up your code editor and make sure to have your final and practice up PHP files open as usual practice that PHP is the plane skeleton we're gonna be using to build what is in final dot PHP final dot PHP or the final example looks like this. We have a Siris of comparison operators and we have some Texan under it and we're using the above comparison operator too. Achieve this result in PHP. So let's jump right into the lecture. At this point, we've been playing around with PHP, variables, arrays and if statements in nearly every lecture so far we've seen the equals symbol. You probably have a basic understanding that it sets of value to a variable like so variable my name and the equal sign After that, a string of text which says Brad, followed by semi Colon. So the equal sign doesn't actually mean. In this case, my name is equal to Brad. It means a sign Brad to the variable. My name from the PHP world. The equal symbol is called an assignment operator. It basically assigns the value on the right to the variable on the left. There are many assignment operators, but we'll get into those once we've been introduced to the many other types of operators in PHP. First, we'll start with the comparison operator. Comparison operators allow you to compare multiple elements. You can compare whether elements are equal, exactly equal or identical, greater than less than plus a few more combinations of the above. Here's a handy, dandy little table provided by PHP dot net. So here you can see I have, in the example a variable and then the operator in between. So the 1st 1 we have the equal comparison operator looks like this. The result is true. If a is equal to be the next one, we have identical, which means true, if a is equal to be and they are of the same type, please note that this is for PHP four and up on Lee and I have a little nifty PHP function spitting out the type the version of PHP you're using. I'm using 5.3 point two, so we're good to go on this one just to expand a little bit on this one. It's a little bit confusing at first because what's the difference between equal and identical is an equal and identical. The same will. Not necessarily. We're gonna jump into that in our final example. But just to give you a heads up, let's say, for example, a is the integer one and B is a string with the number one in between those strings. Those are not identical, so we'll dive further into that a little bit later, the next one not equal. It's true. If a is not equal to be, the next one is also not equal. It's just a different way of writing it. So it's true if a is not equal to be, the next one is not identical, so kind of the same thing is identical. True, if a is not equal to be or they're not of the same type. So same thing if this was an integer and this was a string, and they're not identical. That's how you use that comparison operator. We'll get into that little later as well. The next one is a is less than B. True, if a is strictly less than be, it's pretty straightforward. The next one is greater than which is true if a is strictly greater than be strictly meaning not equal to or greater than because that's the next set of comparison operators. So this is less than or equal to true, if a is less than or equal to be, and the next one is greater than or equal to, which is true if a is greater than or equal to be. Here is an example of how you would use one of the above comparison operators just to get your feet a little wet. So years on Earth 14. If years on Earth is less than or equal to 25 echo your age is less than or equal to 25. So, in this case, because the variable is the interviewer 14 it is in fact, less than 25. If this variable was 25 it would also echo your age is less than or equal to 25. Hopefully that straightforward enough. So feel free to experiment with all of the above comparison operators with some PHP if else and else of statements using the practice that PHP provided in this folder, which we're going to get into right now. So let's go to our code editor. All right, let's start off with our constants and we have the title, which is comparison operators. Next up, we have our custom variables, which is my name and the lesson number, which is 14 in our co dynamic websites Course files folder. Let's go ahead and add those things in here. HB Echo the title copy that pasted between our small tag in the level one heading lesson number. Let's echo our lesson number variable down to the very, very bottom we have our year. Let's use PHP to dynamically echo the date and the year within the date function, and then our name PHP echo my name Variable Perfect. All right, let's go back to our custom variables and let's start adding some new variables that we're gonna be using in this lecture. So years on Earth note that I'm using the camel case. I just added a couple tabs there just cause I wanted to look nice and tidy. When I add the next variables, you'll see what I mean. Not important or required, but looks nice. You'll see. So 25.32 an exact integer the next one. Let's two favorite favorite I meant to say favorite note that I'm using the proper spelling of the word favorite string numb hit tab equals. Okay, so what this means is well, but the variable What? I'm trying to references. I'm not gonna put the integer one. I'm gonna put the number one within a string that's very different than the integer one. And when we're using our identical operator, this is not identical to the integer one, so you'll see how that works A little later on next one birth country Couple tabs Canada. In this case, just start off by putting Canada. And once you want to play with this script that you will be building, you can change this to your own birth country or any other birth country that you want. But for now, just do Canada, so we have the same result. Perfect. Let's go down to our sandbox. You'll see I have a few skeleton kind of starter things for you here. Already have PHP scripts with the Your code here. Comment flag so that you can kind of get started quicker rather than typing everything out . And you're welcome. All right, so let's start with the equal to operator. So in our first PHP script, if in arcs were you need to put an expression here. So if years on Earth is equal to 25.32 then let's echo. Your age is equal to clips equal to and then we can echo the variable here. Since your already in PHP, we don't have to write echo years on Earth so equal to if years on Earth is equal to 25.3 to your age is equal. Two years on Earth. Let's check it out. Final example. Your example. Here we go equal to your age is equal to 25.32 Now, if you changed your very well to 25.31 it nothing would come up because it is not equal to 25.31 Let's change that back. All right, now, it's blast through these other ones identical. So if let's add a else ifa's well and then our fallback else perfect first expression if they favorite string numb is identical to the integer one. Then echo. Your favorite number is an integer else. If the expression will be favorite, string numb is identical to that string. One echo your favorite number is a string called one else. Let's fall back to you. Must have a different hopes. Different favorite number, then one. The integer or string. All right, so let's check that. Oh, let's see what result we get identical. Your favorite number is a string called one, and that is because up here, in our custom variables, we have that string one. What happens if we change the to the integer one? Your favorite number is an integer because it knows that it is not. The string one is not identical to the string one. What if he changes to a different number? You must have a different favorite number than one. The integer or string that is exactly right. Let's change it back. Now let's go back down to not equal if and in our expression here birth country is not equal to Mexico. Then echo you looks Excuse me, senor, from the end with the till the on top. If you're using quota to you can go processing and code entities or use an percent n t i l d e semi colon to get the end with a tilt e. You must not be from around here. All right, so let's check that out. Excuse me, senor, you must not be from around here. And that is correct because my birth country is Canada. What if it was next go Nothing because we don't have anything to deal with that case. But it's working because it's checking to see if it's not equal to Mexico, which is correct. Our rights are not identical. Let's move onto the next one. If let's add in else at the end of that and our first expression will be years on Earth is not identical to 25. Remember that We're gonna put this in a string 25.3 to this string Echo. You are not exactly the string years on Earth. Now note that I put this variable within single quotation marks a single string here because Thea Outside ones are doubles. If I were to put double strings here like this, you'll see something Where it happens, it ah changes the color. Kota lets me know that some things kind of changed here. You might be using a code editor That doesn't let you know. But what happens is in PHP. If you have an opening string, you need to have a closing string of the exact same type, which means it ends that bit of PHP. So right here, this is where it ends. And so we're going to get an error. And these don't really matter. But this does is just creates an error for assigning to you single quotation marks. If I'm using them within double quotation marks now, remember, the same goes for the other way around. If I'm using single quotation marks, which you can very well do on the outside inside, quotation marks need to be doubles. They need to alternate to see how it's the same color. Now the other option is, let's say you're using double quotation marks and the inside. We also want to use double quotation marks. So say, for example, I wanted them to show double quotation marks rather than singles. I can use the back slash before the double quotation marks on the inside like this and then here as well. And we're good to go here. So basically, this allows us to use, uh, the double quotation marks within double quotation marks. Same goes for single quotation marks inside single quotation marks. I need to use the backslash before the each of the instances. And now this allows us to use singles and singles or doubles and doubles. So, like, that wasn't too much. But I wanted to let you know, because it is actually quite important to know you could run across those issues. Ah, lot in PHP. So let's try this out and see what this see, This lets us ah, use double quotation marks. Let's finish the else first. So we're gonna echo. You are exactly the string years on earth whips and in here, and it's gonna use singles inside the double. Now let's check it out. You are not exactly the string 25.3 to D. C. How we're using the double quotation marks here. That's because I put the back slashes before it. What if I took them out. What happens? Let's just have a look broken. We haven't air Big white page PHP cannot comprehend. So let's leave her back. Slash is there. So they were going up. Both examples for you to check out. Okay, so let's move down to less. Then we're gonna use PHP if our expression will be. Lesson numb is less than 15. So if lesson numb is less than 15 then echo. You haven't quite made it to lessen 15 yet. All right, the second out, you haven't quite made it to lessen 15 yet. And that is exactly right, because here we are in tutorial 15 inner quote, dynamic websites, course files folder And we said the lesson numb variables. 14. So we are less than 15. All right. Greater than let's move to greater than you might have a good idea of how this works already. So if lesson numb hopes not. Cookie lesson, um is greater than 10 then echo. You've made it past lesson 10 so let's check it out. Are we greater than less intent? You've made it past lesson 10. That is correct, because our variable for lesson number is 14 less than or equal to. If statement and our expression will be less and numb is less than or equal to 14 if it is less than or equal to 14 let's echo the variable lesson. Numb is less than or equal to 14. Check it out. 14 is less than or equal to 14. That is exactly correct, greater than or equal to and last one here. If statement our expression will say lesson, um, greater than or equal to four in here, we're gonna echo something. If the lesson number able is greater than or equal to four. Lesson number is greater than or equal to four. Save it. Check it out. 14 is greater than or equal to four. Exactly, so that's basically all of the good eggs. All of the examples were using here in the comparison operators and feel free to play around with us. Now he already have something to work with. Change thieve variables, two different numbers, different combinations of strings and integers and change. Your birth country changed the lesson number if you want so on and so forth, even come up with your own variables and just try it out for fun. and see what it looks like. And Ah, yeah, I just have fun with them. Using the equal, identical, unequal, not identical, less than and greater than greater than or equal to in less than or equal to play around with all of them. Change the if statements changed the else if statements, everything like that and, ah, keep playing around with it until you have a good idea. Good grasp on how this whole thing works and PHP. It's incredibly useful. I would suggest playing around in the sandbox just a little bit more. All right. So once you're done doing that scene, the next lecture which will be logical operators, awesome funds, either. 21. Logical operators: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called logical operators. And in this video, we're gonna continue from where we left off in the previous Lecter, which was comparison operators. So we're going to learn a little bit more about the PHP operators and I think, you know, like this lecture. So let's jump right in in your code. Dynamic Websites course files folder. We are in 15 logical operators in your code. Editor, make sure you have opened the final and practiced up PHP files in your Logical Operators folder. Practice up. PHP is thes skeleton and provided where we're gonna be building what is in final, not PHP. Final example looks like this. We have a series of logical operators and the results in under them. So this will make more sense once we dive in. But let's start with our lecture. Logical operators are just that logical. It's like speaking English. They're very helpful when you need your if else and else if statements to be a little bit more complex. So check out the stable provided by PHP dot net. So we have our example name and result in this table. The 1st 1 is the end logical operator, so you could see here. Example variable A and very will be. It is true if both A and B are true, the next one is or true. If either A or B is true, the next one is not. You could see the exclamation point than the variable. True, if a is not true, hopefully that makes sense. That'll probably make more sense once we start coding with it. The next one is, and it's an alternative version. I, too, am percents true if both A and B are true and the last one is an alternative version of or two pipes rather than writing or true if either A or B is true. So here's an example of how you would use one of the above logical operators in a very practical situation. So we have user name password Grable's Johnny Boy in Court E. If user name is equal to Johnny Boy and Password is equal to Court, E then executes some coach. So if this statement is correct, so if user name is equal to this and password is equal to this, so both of these have to be true. For this to evaluate to true, if one either or or both are false, then it will evaluates false and then go to the else statement, which says, Echo your user name and password combination are incorrect. So why don't we jump into a code editor and get her hands a little dirty? So let's start off with our constants and variables and so on and so forth. The title is logical operators. We have our custom variables that we usually add it so my name and lessen numb. Start off with the title paste that in between the small tag and the H one and then the lesson number or in a peach be echo lesson number down at the very bottom ad. The year using PHP, Echo Date, Capital Wife for the full year and your name using the My name Variable PHP Echo my name. Perfect. Let's get into what is most important appear in the custom variables. Let's add our own custom variables, so let's start with user name and let's say the user name, like in the example, is Johnny Boy and then password is equal to 1/4 T now PS worst password ever. Don't actually use this password in real life for anything. And in this case, we're just writing out a sample password. In all cases, when you're using a password variable in your PHP programs or any other program for that matter, you encrypt the password. And PHP has a built in function that can help encrypt the password to prevent hackers from accessing sense of information. But in this case, we're just gonna type it out so you can see how it works. And let's add a couple more variables. So it's a cart total is equal to the integer 19.99 and coupon code is discount, please. All right, so there we go. We have our custom variables. Let's go down into our sandbox and start playing around so and let's start with end. I already have the PHP script here. So if user name is equal to Johnny Boy and password is equal to Corti, then echo paragraph tag and we'll say log in info is correct. All right, so why don't we check that out? So if the user name is equal to Johnny Boy in Password is equal to court e then echo that. And here's your final example or your example. Log in info is correct. Perfect. Now, if you were to change any of the used to something else, you can see nothing happens because it evaluates to false. You can add an else statement there to echo a different statement. If you'd like, let's go down to the or logical operator on. Let's say if carte total is greater than 15 or coupon code is equal to discount, please, then echo. You get a discount so you could see in this case if the car total. So if you've ordered more than 15 presumably dollars worth of goods or you have a coupon code that says No spaces, discount, please. Then echo. You get a discount. So basically, we're assuming in this case we have on online store a shopping cart where if you order more than $15 or you use a coupon code, then you get a discount. Let's have another else statement here and say Echo, you don't get a discount, so if it's less than 15 or you don't have this coupon code, then you don't get a discount. So let's check it out you get a discount? Okay, Cool. So let's Ah, let's change something here. Let's change this to say if the car total is greater than 100 or you have the coupon code discount, please. Let's check it out. So you still get a discount because you have the coupon code discount, please. So why don't we change this to something else? Discount now? So both of these evaluate to false You don't get a discount because you don't have more than $100 in your cart or you don't have the coupon code discount now so you could see how that kind of works. Uh, put those back to their defaults. Now, let's go with the not operator. So let's add a another variable here and say Own dog meaning. Ah, like if you own a dog if you have a dog in your possession. So let's say true own dog is true. If all right, bear with me here. If not own dog, then echo. You do not own a dog else. Echo. You own a dog. Okay, so let's see if this makes sense. The own dog Grabel his Boolean variable, and it's set to true so, if not own dog meaning. If own dog is not true, then you do not own a dog else. You do own a dog so fire just to say if own dog this evaluates to true, then it would technically evaluate the 1st 1 which is kind of inconsistent. Statement. So, if not own dog, if you do not own a dog, is essentially what this is saying that echo the first else this. So let's check it out. You own a dog because own dog is true, and this is checking if own dog is false, so echo you own a dog. Now let's say own dog is false if not own dog and see what happens. You do not own a dog, so own dog is false, so it's checking to see if own dog is not true. That's what the not operator is looking for. It evaluates to true if the expression is not true. So in this case, own dog, the variable is false, and if it is not true, then it is evaluating to true. So hopefully that makes sense. And let's jump down into the end condition. Logical operator. It's the same as the other one just typed differently. If user name is equal to Johnny Boy ampersand twice password is equal to core tea, then echo log in Info is correct. Else echo Wrong log in info. So let's check it out. Log in Info is correct because Johnny boy and password are evaluating to true and last but not least, the alternative or logical operator. Same deal is the other. Or if cart total is greater than 15 or to pipe symbols, Coupon code hopes is equal to discount. Please then echo. You get a discount else echo. You don't get a discount and give it a go. You get a discount because sukar total is greater than 15 or you have the coupon code discount, please. Perfect. So quick. Little recap we've added are constants and custom variables using a password cart, total coupon code, all strings except for less and numb, which we've always done, and cart total, which is an integer as well down here. We added the end or not end and or think that made sentences dragon and or not and and or logical operators, and we did some practical examples with how you would actually use them in Ph. B in a simple, dynamic website. So hopefully that made sense. And if it didn't restart the lecture, that's the beauty of the style of teaching. And hopefully that was valuable to you. I'll see you in the next lecture where we will be covering arithmetic or arithmetic operators, Arithmetic operators, basically math using operators. Alright, Goody see there. 22. Arithmetic operators: Hey, have ready. Welcome back to code dynamic websites with PHP. This lecture is called arithmetic operators and in this video, we're going to be exploring a new type of PHP operator which basically deals with math. So let's jump right in in your code Dynamic Websites course files folder. We are in 16 arithmetic operators in your code editor. Make sure to open your final and practiced up PHP files in the 16 Arithmetic operators folder practised up. PHP is the sandbox skeleton we're gonna be using to code What is in the final dot PHP file that I've also provided final, not PHP looks a little bit like this. We have a series of titles at the types of arithmetic operators, so addition, subtraction, multiplication division and modular lists. And under there we have some texts that were using that specific arithmetic operator to achieve. So let's jump into the lecture Earth Mitic operators. This is where we start getting into some math. It's very basic, but incredibly useful. So check out this table provided by PHP dot net. Like usual, we have the example name and result. The first line we have variable A plus very will be. This is addition, so the result is the sum of A and B. We basically will know how to do all of these because it's just pretty straightforward math . So 1st 1 is addition. 2nd 1 is subtraction, so the difference of A and B A minus bi 3rd 1 is multiplication, the product of A and B a Times B fourth division, the quotient of A and B. So a divided by B and the last one is something that many of you may not have heard before . I know I didn't when I started learning some arithmetic operators module ISS. So it is the remainder of a divided by B, so a module iss be so. The module is operator is usually a pretty confusing concept at first, but math form dot org's provides a pretty good explanation right here. The mod or modular operator and computer languages is simply the remainder. For example, 17 module ISS three equals two because 17 divided by three is equal to five. So the remainder is, too, which in turn means 17 equals three times five plus two. So hopefully that makes sense. Here's an example of how you'd use one of the above arithmetic operators. So every PHP script, Berthier and this year invariable. So we have Berthier. I put 1988 and this year, So I'm using the PHP date method with the year. So my age equals in brackets this year. So it's getting the current year minus 1988. So my age will have this year minus 1988. Then I echo my age, and that will echo the person's age. Whose birth? Years? 1988. So let's jump right into our code editor to start doing some math. Let's start out doing the usual Add your Constance and your variables that the constant title is arithmetic operators, and in this one we're going to just add the usual custom variables, which is my name and lesson number. Add the title right here, and also add that to the small tag within the H one tag. The lesson number or the tutorial number is PHP echo lesson numb and then at the bottom. We have our current year PHP, echo date year and name PHP Echo my name. Good to go. All right, let's get into our sandboxes where the fun happened So 1st 1 we have addition. Remove the your code here. PHP comment. And let's add some variables within this PHP script. So let's start with a A equals seven. Let's add B and say b equals 19 and C is equal to in brackets. A plus hopes a plus Be so see, will The sea variable will include Ah, this addition a plus B and let's echo the result echo A plus B is equal to see. Very simple. Let's check it out. Array. So your example seven plus 19 is equal to 26. That is correct. Thank you. Ph. B. All right down to subtraction. Let's add three more variables. We're gonna use a equals seven b equals 19 and C is equal to hey minus B. Now keep in mind you can change these variables. I'm just recycling a B and C and just putting the same numbers in this case. But you can change these to experiment with different math, so echo a minus B is equal to see. Check that out. Seven. Minus 19 is equal to negative 12. All right, multiplication a equals seven b equals 19 and C is equal to a multiplied by B and then we're gonna echo the result by saying a And then I'm gonna say times using the HTML special character. Whoops and percent a Times B is equal to see. Let's check it out. Seven times 19 is equal to 133 Ray Division. We have our A variable seven b 19 and see a fighter by B. Take it out. Oh, whoops. Can't check it out yet. You need to echo a divided by B is equal to see. Check it out. Seven. Divided by 19 is equal to 0.36842105 to 632 cool and last but not least and most confusing module ISS. So we have a single to seven. B is equal to 19 and C is equal to ah, a module iss be and then we're gonna echo the result. A ma jealous B is equal to see. Check it out. Seven Modulates 19 is equal to seven Cool, So feel free to go through and just play with the different types of arithmetic operators in the sandbox and just see what kind of results you can get. You could do. A whole bunch of Matthew can add different types of operators in one so you can do this and then you could say, divided by B module iss si or a whatever and, ah, just experiment. This conduce you basically any type of math and ah, it's really useful when you're coding your dynamic websites. And so hopefully this lecture was useful to you play around in the sandbox and I'll see in the next lecture. 23. String operators: Ola Autos Bienvenido Ah Ko Dynamic websites with PHP This lecture is called string operators and in this video, we're going to be adding another operator to our arsenal of PHP awesomeness. Well, that's a little this Sorry about that. In your code. Dynamic Websites course files folder We are in 17 string operators in your code editor. Be sure to open up final and practice dot PHP in the 17 string Operators folder within your code Dynamic Websites course files folder practiced at PHP as usual, be the sandbox that we will use to build file dot PHP Final example Looks like this boom concoct nation operator Olan mi amigos Can Captain ating a Simon operator Olan mi amigos the hope that didn't really make sense. But anyway, we're gonna be using the concatenation operator and the contaminating assignment operator. They sound like a mouthful, but they're actually quite simple, very useful. Let's jump to the Lexx. Like I said, this one is nice and simple. There are only two string operators. The 1st 1 is called the Can Captain ation operator looks a little bit like this, like a dot or a period which combines the value of the right argument with the left argument. So let's look at it like this. So we have variable A We're assigning Ola notice the space and then we have the be variable and we're assigning a So we're assigning the value of A which is Ola with the space And then we're using the concatenation operator and then afterwards we have another string of text that says me amigos. So if I echo be, it will print or echo Hola, mi amigos See how that works. So basically the concatenation operator will assign the value afterwards to the variable before it. So you see here like I already showed you, we got very well be the value is A and MI amigos So were assigning this attacking this onto the end of this string. So it's creating a new string itself which Prince Olam amigos. So the second operator is the Kyne Canton ating assignment operator Looks like this a period and unequal sign which up ends the value in the right with the value in the left like this. So it's basically a simpler version of the top. So variable a is ola with the space we're also doing another one here, just a variable A. But instead of just the equal sign were adding in Katyn eating assignment operator. So period and equal sign mi amigos. So instead of just rewriting the variable cause if you were to just break a twice and then basically the second instance of this variable and the value of of the variable, it's gonna overwrite the 1st 1 But in this case, it's going to upend the value to the initial or the first variable. So a echo a this prince. Hola, mi amigos. So the Katyn eating assignment operators considered an assignment operator, which will be learning more about in the next lecture. But for now, we're just gonna play with these two. So let's jump into our code editor. All right? Like usual. Let's add all the old cleanup stuff, constants and variables and so on, so forth. Take up moments to do that. We've got the title. We got our custom variables, your name and lesson number. Feel free to zip through this part if you've already done it, or you just want to keep practicing that school. I'm just going to be doing this and add the title down here again. Boom! Lesson number B HB Echo. Let's echo that lesson number. Save. That's down to the year. PHP Echo date. Why? Why there it is. Okay. And my name using the variable that I set PHP echo my name. Boom. Done Sweet house fast. All right, now the good stuff. Let's go to the sandbox. You can catch a nation operator. Let's do it. Let's add a couple variables in here So we're gonna have a equals Ola with a space B equals me amigos and then see is equal to a can Kathy Nation operator Be now, let's echo. See? See what that looks like. Make sure to check it out and practice that PHP. Hola, mi amigos. Now let's just try a little something out here. Let's take the space away. What does that do? Save it, Check it out. It has no space in between here. It's because this was the first variable. This is the second. We didn't add a space in either notice that this doesn't matter if there's any spaces here or not, it doesn't add any spaces. Nothing happens. However, if you were to add a space in the 2nd 1 beforehand that works as well, but you need to make sure to have a space somewhere. So that's the concatenation operator. Let's try the King Canton ating assignment operator. So we got Variable, a sequel to Ola Space. Be sorry A Can Captain Eating assignment Operator, Meet Amigos And now let's echo a. There we go see what it does. Hola, mi amigos. Let's try something interesting here. Watch this. What if I didn't want to just set the variables and write three lines of code like this? What if I wanted to just minimize it a bit? So it's tried out? Watch this. Let's echo a captain aiding assignment Operator me amigos. Scared of the 2nd 1 So I just minimize the line there. We'll see what that does. Same thing. I just took out a line pretty pretty cool. So yeah, that's basically it. That's the concatenation operator in the Kit Kat needing assignment operators. Very simple. Feel free to try. Met with different variables, numbers, strings, sort of good stuff. The swipe and ah, yeah, I'll see in the next lecture where we're gonna learn about some assignment operators, which are pretty awesome. See there when the moon hits your eyes like a trying pizza pie. That's amore A oh, I think still on 24. Assignment operators: yo already Welcome back to code dynamic websites with PHP. This lecture is called assignment operators and this is the one where we're gonna wrap up our section on PHP operators. This one's a very useful one, So pay attention in your code. Dynamic Websites Course Files folder. We are in 18 assignment operators in your code editor. Make sure to open up the final and practice up PHP files in the assignment operators Bolder and your Code Dynamic Websites Course files folder. As usual, practice up. Each piece of sandbox final dot PHP is the final example. Final example Looks like this. We have a Siris of assignment operators and some values that were using our PHP to get that results. So let's jump into the lecture. Simon Operators assign values from the right argument to the left argument, usually in the form of variables. The basic assignment operator we've used a lot is the equal sign, which assigns the value on the right to the variable on the left. Here is a table of more assignment operators, so we have the assignment same as and description. The 1st 1 is the addition assignment operator, So the plus sign the equals sign. It is the same as a equals a plus B. So this is a shorter way of doing the same thing as this. The next one is a subtraction assignment operator. It looks like a minus equals B, which is the same as a equals a minus bi. 3rd 1 is the multiplication assignment operator. A times equals B, which is the same as a equals. A Times B fourth division a divided by equals B, which is the same as a equals. A divided by B module ISS. The funny little module iss a modulates equals B, same as a equals a module is B and last but not least, concatenation. A dot equals B. It's the same as a equals a dot b dot meaning can Katyn eight. Hopefully, that made sense. So here's an example of how to use one of the above operators, So PHP script variable A equal 71 very will be is 36. A minus equals B. If you go that you get 35 because 71 minus 36 is 35. The reason why I know that is because BHP told me all right. Code editor time. All right. Add your title and your constants and variables and all that sort of good stuff, and make sure to add them here in the useful places by now. This should just be boring and simple for you. You should be a pro at this. You might even be fast forwarding this part because you've already done it all beforehand or something. Or maybe not a school to Nori's B h B a go lesson number, right? Whoops. On the bottom. We got our year. PHP Echo Date year. Perfect Name. BHP Echo. My name. Perfect Sandbox time. All right, start up with our addition. Assignment operator. It's had some variables. We got a equals 30 b equals 50 and then let's go a plus equals or the addition assignment operator Be so basically, this adds B and a together and re assigns the It's really hard to speak and type the exact same time value to okay adds being a together resigns value to a So if I were to echo that echo A let's check it out in the practice up PHP example. Additional time operator 80 because 50 plus 30 is 80 and we did that by just going. Ah, a addition. To sign operator, be reassigns value to a using some math cool subtraction assignment operator. Let's add the same variables. Just gonna copy and paste. Save some typing 30 and 50 for A and B A is gonna be minus equals or the subtraction to Simon operator be. Does that get us Echo? A. Let's find out minus 20 or negative 20. That's because 30 minus 50 is negative. 20. Multiplication assignment Operator. It's at our variables 30 and 50. You can always change these two. Whatever numbers you want. I'm just using 30 and 50 because it's simple and consistent. A multiply equals or multiplication assignment. Operator. Be echo that. What do we get? 1500 Because 30 times 50 His 1500 You're so smart. PHP. All right, Division assignment Operator. We're going to do the same variables. 30 and 50 A divide equal or division of Simon operator. Be echo A. What do we get? 0.6 because 30 divided by 50 is 500.6. Ma Jealous assignment operator 30 and 50 A module ISS equals Be on that is going to get us 30 because 30 module list 50 is 30. I don't really know how that happens, but Ph. B is right. Can Captain ation assignment operator? This one we've touched on in the last lecture? A is equal to a lot, and B is equal to me amigos and then a cat nation. Ah, Simon. Operator, be echo. Okay, What do we get? Hola, mi amigos. So I kinda zipped through that one because they're just some fairly simple examples. But these are very useful operators. All of these assignment operators. You're gonna be using them. And I encourage you to try an experiment with how you can use thes when you're coding a dynamic PHP Web site. Because you can be efficient with your coding When you use these types of assignment operators a few if you can minimize 10 lines down to eight lines or Dickenman minimized 100 lines down to 60 lines, that's that's really good. That saves you time and it saves. Ah makes the program run faster, screwed coding practice. And that's kind of how you can use these operators, these assignment operators. It helps you be more efficient and smart with your PHP coding. Hang in there because in the next lecture. We're gonna be diving into a whole new section called PHP Loops and ah, sounds kind of fun. So let's check it out. See there. 25. While loop: Hey, already welcome back to code dynamic websites with PHP. This lecture is called while loop and in this video we're going to be jumping into some new PHP material. So let's do this in your code. Dynamic Websites Course Files folder were in 19 Wild Loop in your code Editor. Make sure open, final and practice that PHP in the 19 while lip folder practice dot PHP is the sandbox and final dot PHP is the final example which looks like this. We have the numbers 10 through 20 and we're using the wild loop to give us this result. So why don't we jump into the lecture so we can learn a little bit about the while loop when coating ph B loops can be fantastic. Basically, you can read a piece of code to repeat itself again and again until a certain condition has been met. There are a few types of loops and PHP, but in this lecture we're gonna learn about while loops. Here's how a while loop works while a condition is true, executes him coat. At this point, you probably have no idea how to actually use a while loop in PHP. But That's okay. Let's dive into how you actually use it. So let's say you want PHP to echo the numbers from 10 to 21st you need to set a variable with your starting number. So here's our PHP script. Let's set a variable with starting number. We're going to say 10. Then you need to start your while loop with a condition, so you need to give your while loop a condition. And in this case, we want our condition to say, while my starting number is less than or equal to 20 the condition is true to help clarify . As long as the variable starting numb is less than or equal to 20 keep on Lupin. So here's our PHP script. Again, we have our variable with starting number and our while loop skeleton with a condition, while the starting numb is less than or equal to 20 Executes. Um, code Now you may be thinking, are starting Number is 10 and it will always be less than 20 Dumbo. Well, each time we loop through our function, we will tell PHP to increment. Are starting number by one, therefore eventually are starting. Number will be equal to 20 are conditions says to stop looping Once are starting number is larger than 20. We need to do this to prevent an infinite loop, something you most definitely don't want. An infinite loop means your function literally will run forever, which can freeze up, computer your computer and cause a whole lack of other issues. So let's tell. PHP to echo are starting number able, then increment the variable by one. Here's our PHP script. Again, we have a starting number, while the starting number is less than or equal to 20. Echo the variable on the screen. And then we're gonna can captain eight a break tag at the end so that each new number will be on its own line. So echoes starting numb Can Katyn ate a break tag, then increment the value by one. You do that in PHP by adding a plus plus after the variable. As long as the variable is an integer, so in PHP, you can increment and decry mint variables like so. A plus plus or variable plus plus adds one to the value of the variable each time through variable a minus minus subtracts from the value of the variable a each time through. So this adds plus one. This subtracts one. So if I coated this correctly, the coach of Echo the numbers 10 through 20 on your screen and stop at 20 keep in mind you can use any of the operators refused in our past lectures as the conditions that need to be met in the wild loop. So again, here's our final example. The numbers 10 through 20. So why don't we jump into our code editor and see if we can achieve the same result? So in your practice of PHP file, go ahead and I'd your constants in your custom variables. I've auto filled them this time so I don't have to take them all out. But feel free to add your constant with the title, the name and the lesson number. And then remember to echo your constant between the title tags and the small tag here and at the very bottom, you want to echo your date and your name. Your practice. That PHP file will have some HTML comments in replacement of these, so you will know where you need to add that coat. So go ahead and add those And once you're done, let's jump into our PHP script right here in the sandbox. So why don't we start by setting a variable with your starting number? So let's say starting numb is equal to 10 while starting numb is less than or equal to 20. Okay, here's our wild up skeleton, and we're going to say the condition is starting. Numb is less than or equal to 20. So while that's the case, echo the value of the variable on the screen using the echo function starting numb. And then we're gonna can captain eat a break tag at the end of each line. Then we want to increment the value of starting, um 51 And we do that like so starting none plus plus Save that. Now, why don't we check that out in practice up HP, see if you got the same thing. Boom. There it is. 10 through 20 if you got the same result than you nailed it. If not, go ahead and go back to the code editor. Make sure you have everything tiptoe properly. Maybe you're missing a semi colon so on so forth. And that's basically it for the basics of the while loop. You can also go in and change the value of the starting number. And you can change the condition to be, you know, less center equal to a certain number. You can change us to 100 could be a negative number. And you can de crimen to the value using the minus minus. Change your labels and your conditions so on so forth get comfortable with the wild loop. And in the next lecture, we're gonna be covering the basics of the four loop. See there. 26. For loop: Hey, everybody, welcome back to code dynamic Websites of PHP. This lecture is called Four Loop and in this video, we're going to continue from where we left off with the wild loop and we're gonna learn a little bit more about how to use PHP loops. So let's do this in your code. Dynamic Websites Course Files folder We are in 24 Loop in your code editor. Make sure to open up the same folder 24 loop and open final and practice that PHP practice up. PHP is the sandbox, which you were going to be using to build what is in final dot PHP. Final PHP looks a little something like this. Here's the final example. We have a list saying number zero all the way through 20 and we're using the PHP four loop to achieve that results. So let's jump into the lecture. Four loops are a little trickier to wrap your head around, so hang in there for loop is used when you know in advance how many times the script should run, says W. Three schools. The syntax looks like so four initialized counter, then test. If true, then increment the counter and then inside your curly braces execute some code. So essentially the four loop will initialize where the loop will start counting by adding of value to a variable. Then evaluate a certain condition to test if the condition is either true or false. If the condition is false, the loop will stop running, then increment the value by one each time we loop through. So if we want to have our four loop spit out the numbers zero through 20 we could code the following four A is equal to zero, so initialize the counter, then a less than or equal to 20. So we'll test if this is true. So if a is less than or equal to 20 then increment the counter and then echo the number or the text number and then the variable A and then a break tag. So if coded correctly, this should echo the number zero through 20 on your screen and stop a 20. So if we look at the final example, that's exactly the case. So let's commodore code editor so that we can achieve this ourselves. All right, so here, in practice that PHP if I've pre filled the constants, custom variables and I have echoed the titles here. The lesson number here and down here of Echoed the Date and the My Name Variable. Go ahead and do that yourself. And then once you're done, let's jump into the sandbox. All right, so here in our sandbox, let's code our four loop skeleton. Very simple. Here it is. And so the first argument and the four loop is too initialized the counter. So what's out of variable? Let's call it a and let's say it is equal to zero, so we'll initialize the variable at zero. That's where it's going to start. Semi Colon. The next argument is the condition to test, if true. So let's say a It's less center equal to 20. So this is going to check to see if a is less center equal to 20. Then the third argument is to increment that counter. So then a plus plus, now inside here, we're going to execute some code each time we looped through this four loop, so we're going to simply echo number, then the variable A and a break tag so we could break each loop on a new line. So say that, and let's check it out. In the practice of PHP, there's this super simple super easy. So that's essentially how you use the four loop. And remember, the four loop is used when you know how many times you want a loop through something. So if you're counting set of numbers if for implementing or decry MENTING a set of numbers , you could change the where you want thievery able to initialize and you want you could change the condition to test the number could be different right here. And so, yeah, that's essentially the four loop. It's actually pretty simple. Once you get it going. The only thing confusing about it is just understanding the arguments here inside the parentheses. So, really, that's it I'll see in the next lecture. 27. Foreach loop: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called for each loop. And in this lecture, we're going to continue again from where we left off in our previous lecture, which was thief four loop. And before that was the wild loop. And this one is thief for each loop. A very popular loop, and I think you will like it to check it out in your code. Dynamic Websites course fast folder. We are in 21 for each loop in your code. Editor, make sure to open up the final in practice up. PHP files in your 21 for each loop folder in the course files folder. Practice up. PHP is the sandbox you're gonna use to build what is in final dot PHP. Find about PHP as usual. Looks like this in our final example. So we have three statements. One is I love the handlebar. Then I love the Salvador Dali. Then I love the Fu Manchu like this we're revisiting the mustache is so each of these things were using the for each loop to dynamically spit this text out In order for you to understand this better. Let's jump into our lecture, the for each loop. This loop is a very popular loop and is used extensively in database driven websites. The purpose of a for each loop is to loop through each key value pair in an array W three schools. Do you need a refresher on a raise? Head back to the rays lectures to refresh your memory, but don't worry when you head there. I've used the PHP get request up here, using a query string to make sure you head back to the for each loop. A lecture. All right, the syntax for the for each loop looks like so for each array as value and then we execute some code looks pretty simple. So basically, here's what happens during each loop iteration. First assign value of current array element to value to value is echoed on the screen. Three. The array pointer then moves to the next element within the array. Four. Repeat from the beginning until final array element. So let's use a real world example of how to use for each loop. So we need to create an array. So let's resurrect. Our array of mustache is so mustache is array handlebar, Salvador Dali and Fu Manchu. Then we're gonna loop through. The mustache is array, so for each mustache is as mustache and then output each individual value echo. I love the mustache break tag, so mustache contains each individual value within the array. Because we said in our for each loop loop through each array element in mustache is and a sign each of those array elements the variable mustache, and then you can output each individual one as we loop through the array and then it finishes at the end. So if coded correctly, this should echo the three mustache is in the in the array on your screen. And as we've seen already, it does, in fact so why don't we jump into our code editor so that we can see how to do this ourselves? So at this point, I thought you might be bored with doing all the constants and the variables that were using in every single one of these examples like that, echoing the title and lesson number, so on and so forth. So I've provided that for you in this practice of PHP file, so you don't have to waste your time doing it. Obviously, you need to change your custom variables. Uh, the only one really you need to change is the mining variable. Lawson Numbers should be good to go. All right, let's just jump into our sandbox. So let's start off with our mustache is array and let's add some array elements. Handlebar will be the 1st 1 and then we're gonna add the's Salvador Dali. After that, we will add the Fu Man Chu. So there's our mustache is array. After that, we're going to use the for each loop to loop through each of these array elements. So for each mustache is as mustache and then we can simply output. I love the mustache break, so that's going to say I love thee and whatever mustache we are in the rain. So check it out in the practice of PHP Fa. There it is. I love the handlebar. I love the Salvador Dali and I love the Fu Manchu. As I said before, the for each loop is incredibly powerful. It's very simple, but it's powerful because you can look through any type of array you gonna loop through multi dimensional arrays, associative raise all that sort of stuff, and it's used heavily in database driven websites. But here is the basic bare bones version of how you would use the for each loop. Hopefully that helped seeing the next lecture. 28. Do while loop: Hey of ready. Welcome back to code dynamic websites with PHP. This lecture is called Do while Loop. And in this lecture we're going to wrap up our section on loops and continue from where we left off in our previous lecture, which was the for each loop. So hang in there and let's learn a little bit about the do while loop in your code Dynamic Websites Course files folder we are in 20 to do while loop in your code editor. Make sure to open the final and practice a PHP files and the do while Loop folder and your code Dynamic websites Course files folder practice Stop PHP is a sandbox, which we're gonna be using to build what is in final dot PHP final dot PHP. It looks like this final example do wild loop. So we have the number one through 10 and we're using the do while loop To achieve this result, Why don't we learn a little bit about the do while loop before we jump into our coded? Or All right, the do while loop is a bit like the wild loop, but there's one major difference. The wild loop will only start if the condition is true, whereas the do while loop will always execute the first time and then evaluate whether the condition is true. Afterwards, here's what the syntax looks like. Do executes some code and then after the second or the closing curly bracket while and then in parentheses, a condition to be met. End with semi colon. So let's look at a real example. So let's set a variable. We're gonna say I is equal to one. Do echo the number and then the variable I with a break tag afterwards to separate the loop on a new line every time and then increments the I variable by one every time you loop, Then evaluate this condition. Repeat the loop. If true, while I is less than less than or equal to 10. So if coded correctly, this should echo the numbers 1 to 10 on your screen. So let's check it out. There it is one through 10. So why don't we jump into the code editor to see what this is actually like? Hands on. All right, so when are practiced up? PHP file. We have our constants and custom variables that have been auto populated for you. Make sure to change the my name variable to your name. And now let's jump in to the sandbox. Start off by adding a variable called I and give it the value of the integer one. After that, let's code our do while loop skeleton. So do opening and closing curly brackets and then while and then we'll have our condition to be met in here. Semi colon. You can also space the cell like this if you like, but I think it looks a little better like this. Okay, in the opening closing curly brackets, that's echo some text number and then the variable I and then an HTML break tag to separate each on a new line. This should be number, not numerous. And then after that, we need to increment the I variable by one every time, while by is less than or equal to 10. So what this is saying is the first time this loop is introduced to us, echo the number the first number and then increment the variable by one. And then, while I is less than or equal to 10 keep on looping. So the 1st 1 gets executed and then on the second time through we check through the while part of this do wild loop to see if the condition is true. If so, keep looping. If not, stop. Let's check it out in our practice up. PHP. There it is. Number one through 10. Using the do while loop was a short but sweet little lecture. But hopefully that was useful to you. And I will see you in the next lecture. 29. Intro to PHP functions: Hey, everybody, welcome back to code dynamic Websites with PHP. This lecture is called Intro to PHP functions and in this video were in a whole new section . Now we've left behind our section on PHP loops and now we're actually gonna get started with some introductory level function tutorials. So let's jump right in in your code. Dynamic Websites course files folder. We are in 23 functions in your code editor. Make sure to open the final and practiced up PHP files in the 23 Functions folder practised up. PHP is the sandbox that we're gonna use to build. What is in final dot PHP final dot PHP. Looks like this Here In our final example, we are using four built in PHP functions sort are sort string to lower and Shah one and we're gonna be experimenting with those in our sandbox. So why don't we jump into our lecture to learn a little bit more about PHP functions. So if you've made it this far, congratulations are in order. We've covered a lot of ground and are PHP coding skills are becoming much more refined. End skillful. I'm gonna go ahead and say that functions are the meat and potatoes or beans and rice. If you're vegetarian of most programming languages, they are fundamental. When cooking a tasty PHP dinner, Choose a in PHP. There is a massive library over 1000 of baked in functions. Pun totally intended that do everything from printing text on your screen to adding information to a database and a lot more. It's good to know that there are two types of PHP functions built in PHP functions and custom functions. You can write your own custom. PHP functions pretty cool. So remember echo and print. Those little guys are functions a few important facts about functions. The function is a block of statements that can be used repeatedly in a program. Also, ah, function will not execute immediately when a page loads rather it just gonna sits there waiting for you to call it. Which brings me to the last point. A function will be executed by a call to the function, and that is a reference to W three schools. So let's take a look at the basic syntax of a function. So here we have the word function and then a space, and then a function name, followed by an opening and closing parentheses. And then you're opening and closing curly braces inside the curly curly braces. You execute some coat or you put your code within the function. So please note that a function name can start with a letter or underscore not a number. And here's a hot tip. You can name the function. Whatever you wish. Just try and have it reflect what the function actually does. So if you're calling a PHP function that reorders your array in alphabetical order, don't have the function be called awesome sauce. You know what I mean? Hopefully, that made sense. Okay, so let's just look a little bit into PHP sort function. So this function allows us to sort an array in alphabetical order. First, let's create an array. So here we have dinner and we haven't array, and we have our meat, potatoes, beans and rice all in one dinner array. So then let's run our array through the sort function. So we have our array here in our variable and then add the array is a parameter to this sort function like this sort dinner. Now all we have to do is echo our ray on the screen using a four each loop, which we've covered, like so. So we have a four each loop dinner as ingredient and then echo ingredient and then break onto a new line. So if we coated it correctly, the above will echo the array in alphabetical order, like so beans, meat, potatoes and rice. If you're looking to sort your array in reverse order, you can use the PHP are sort for reverse sort function. Feel free to read more about thesis, er, function and other sorting functions using P following links. We won't be covering all of the built in Petri functions in this course because that would take an incredibly long time. Besides, it's fun to be in a situation where your programming and then you think, Hey, I wonder if there's a PHP function that will do this for me. This is why I will leave you with the curiosity to experiment. Google is your best friend, and you may also refer to this directory rate here. So let's jump into our code editor. Make sure to change the my name variable to your name. Everything else should be set up good to go for you. Now let's go down to our sandbox. And why don't we start with the sort function? So let's create an array. Call it dinner. And in our ray, we're gonna have a few items one's going to meet and actually know what you can. You can put whatever items you want to hear. You can have the same as mine. Or you can put your favorite dinner items or ingredients in here and as many as you want, as long as you put them in a string. Separate them by, uh, comma, and then you can sort them pretty cool. So potatoes, beans and then rice cool. So then we want to do is add theory A as a parameter to the sort function So sort. It's a built in PHP function, but we need to put the variable as a parameter right here and sir function. Last but not least, we need to echo the sorted array, and we know how to echo an array on the screen. We use a for each loop, so for each dinner, So for each item in the dinner array, store it in an ingredient variable and then echo ingredient and then break. So I put that in strings here because I just I wanted to put the break take at the end. You could also do it differently by contaminating it at the end. But I just put it all in strings because it should work as long as you put it in double quotation marks. Good. So why don't we check it out? And the practice of PHP file there does so sort beans, meat, potatoes and rice. If you use different ingredients, then you can You'll see that they will have sorted in alphabetical order otherwise, uh, this is correct. And enough about 1/4. So why don't we go down to our sort here in our sandbox? Now, we don't actually need to right out the dinner variable again here because we've already done it up here. In fact, we could have put the dinner variable way up at the top of the page in above all of the HTML. But, for example, I just put it here. So because I already wrote a art dinner array, we don't actually need to re write in, So all we need to do is sort sorry are sort our array, which is dinner, and then after that print or echo a sorted array using for each loop. So dinner as ingredient and then echo ingredients and then a break tag. So let's give that a look in our sort. Rice, potatoes, meat and beans. Perfect. Let's go to string toe lower so string to lower basically takes all of your text in a variable or whatever, and it's takes makes everything lower. Case takes all the capital letters and just put some all lower case useful if you're wanting to do things like if you're logging in and, ah, a user name is case sensitive and somebody typed, you know had their caps lock button on, and they typed in their user name in all caps. You can you string to lower Teoh, filter that user name and make sure it's lower case so they don't have to re type. There is your name, so why don't we just do an example here? Let's say text and let's say twinkle notice. I'm using caps in some of these cases, twinkle little star all caps right there at the end, just shaking it up. So let's run the text are able through the string to lower function and then reassigned the value to the text variable. So here we have text again and we're going to run the original variable string to lower. And then we're gonna put texts as a parameter here, running it through that function and then echo text will see we get Twinkle, twinkle, little star all lower case Perfect. So now let's go down to shock one. Now, what is Shah one you may ask. Well, basically, shall one calculates the sha one hash of a strength kind of vague, but basically what it does is it returns a value of a 40 character has a decimal numbers. So Sha One is kind of a way of how you encrypt a string of text or, say, a password. For example. It's not the most secure, and there are much more secure methods of using encryption for passwords. But shall one is a very simple PHP function that basically encrypts your password into a 40 Character has a decimal value, So why don't we just try this back in her code? Editors were gonna say password is equal to my password just like that. Let's say That's what your password waas. Your password is terrible. Echo before password and then a break. Take. So this is just gonna let us tell us what are current password is now, Keep in mind, Shaw. One doesn't change your password. It just encrypts it so you can't easily tell what your password is. So if someone were to try and they hacked into the database and they saw your database table that said user name password, they saw your user name was Jon Snow. And then your password was white Walker. Then there you go. They know they can. They can use your user name password combination. However, if they logged in aside your user name was John Snow. Password was a bunch of random characters. That's they can't log in with that. If they copied that, those 40 characters pasted in the password field tried logging in no dice is not gonna work because usually what happens is when you log in, you type in your password in the password field hit, submit PHP, then encrypts up password, checks it against the database to see if it matches the encrypted password and then logs you in. If it's correct. So basically, you. If you just saw the 40 character value the show one version and copied and pasted in your password field, it's not gonna do anything, cause then it's going to try and encrypt that. So it's double encrypting it, and it's not gonna work. So basically they need to know how to reverse the Shah one. Encryption And there are ways of doing that. There's some pretty smart hackers out there, but here's just a very simple introduction to password encryption using Show One. Okay, so let's go password again, and then we're gonna say, equals Shaw one and then in here run password as a parameter of show one and then echo after and then password. So say that and let's check it out. Here we go before my password after 40 characters of randomness, and that is your encrypted password. So this is what it would store in the database, theoretically, and this is what you'd log in with. So when you log in, type this in, and then the in foot Ah, in the back end, PHP would encrypt it using show one. Test it against the database to see if it matches and then you're good to go. So basically, there you're there. Just four simple examples of PHP functions built in functions. Um, and hopefully that was helpful. In the next video, we're going to be playing around with some custom functions, So we're gonna build our own custom. PHP functions pretty cool. See there. 30. Building custom functions: Hey, everybody, welcome back to code dynamic Websites with PHP. This lecture is called custom functions. And in this video, we're going to continue from where we left off in our previous lecture, which was intro to PHP functions where we learned a little bit about the built in PHP functions. And now we're gonna learn how to actually create our own custom. PHP functions pretty cool. See in there in your code Dynamic websites course files Fuller. We are in 24 custom functions in your code. Editor. Make sure to open the final and practice a PHP files in your 24 custom functions folder. Practice up. PHP is thief file we're going to use to create what is in final dot PHP final dot PHP Looks a little bit something like this final example. We have some text here that says, Surf's up, Grab your board and we're using a PHP custom function to give us that text, and I'll reveal how to do that after we cover our lecture. So let's jump right in. While PHP has a massive library of built in functions you have at your disposal. Sometimes you just need to build your own functions for both small and large tasks. Think of a custom function as a mini program that performs an action for you. Better yet, think of a custom function as a cute little robot that does a specific task. You tell it to do so. Let's look at the basic syntax of a custom function. So in our PHP script, you need to type the word function and then name your function we're using. However you want whatever you want to name it. Keep in mind that this can be whatever words you want them to be, but there are no spaces allowed. I like using camel cases. You can see here the Capital Seed Capital F lower case First word here just because it's easier to read. And it's a pretty common programming convention. After that. You put your opening and closing parentheses in case you want to send an argument through that function, which will cover in the next lecture. And then you have your opening and closing curly brackets or curly braces, as some call it. And in between those curly brackets is where you define what your function will perform. So there are two important things to know about functions. There are functions that require arguments, as they just mentioned, and their functions that don't require arguments. So let's start by building a custom function that does not require an argument. So here we have our PHP script. Let's start by building a function. So I'm gonna cut, uh, type the word function here, and then I'm gonna call this function. Hang 10 in the curly brackets, I'm echoing the text, surfs up, grab your board. After the closing curly bracket, I'm calling the function by typing the function name, followed by its opening and closing Curly. Sorry, opening and closing parentheses and then a semi colon. Note that you can call the function essentially anywhere in your page. It doesn't have to be directly after it, because usually what you do is you build your function or a list of function, say in a separate PHP file, and you include that file in a specific page. And when you need a specific function, all you need to do is just call the function by just typing the functions name, so keeps your page really clean, and it's you can use and recycle that function over and over and over again all throughout your site, and threat your program because you have your function pre built somewhere else, whether it's at the top, your page or whether it's in a separate script altogether. And then you could just call the function. It's really simple. So why don't we jump into our code editor and build our own custom function? All right, here we are, in practice, up PHP. Make sure to change the mining were able to your name, so it reflects your name properly. You don't have to if you want to keep my name that school and let's just jump down in our sandbox. In between are PHP script. Let's start by reading the word function. Let's call this function. Hang 10 parentheses, opening, closing and then you're opening and closing curly brackets inside there. Let's just echo a simple string of text service up. Grab your board. All right. So instead of just me calling the function like this, which I'll show you what it looks like. So here's the practice of PHP Page, and you could see the Texas here serves up. Grab your board. But there isn't really much use in me just writing out of function and then calling the function like this because I could have just type the text out and skip the functional together. So how would we actually use this custom function that it makes sense? Well, here, let me give you a Let's try like a little simple example of how this could be used. So let's create a variable. Let's call it, Surf is up and let's set that to true. So the variable surface up is equal to true. Now let's use our nifty if statement if surf is up. So if the surface up true, then we're gonna hang 10 pretty cool. And after that else, let's remove this last hang 10 function call Echo Bomber bra. So here we got our function up here. I could have included this function, say, if I used the PHP include up here. And I said, include, uh, functions that PHP and I had my function. My hang 10 function in that separate file would be the same as if it was right here. Just keeps it clean, and after that I have a variable checking to see if surface up. If it's true, then, Ah, we're going to use their f statement to test to see if surface up. If it is, then we're gonna hang 10 else. We're gonna echo bomber bra. So basically, you know, this variable could be dynamic if you had a script built where you were checking to see if the servers up and the variable could change from true to false and then based on our if statement and what the value is of surface up, you'd get a different result. So let's say surface up was actually false. Let's check it out, Barbara. But if it's true, check it out. Serves up. Grab your board. So there it is. That's just a really simple example of a custom PHP function. You could literally do anything inside your custom function. I'm just doing a simple Kotex, but you could do if statements you could do math. You could do literally anything. The sky's the limit, and you could make your functions really incredible. And one thing of making your custom functions a bit more powerful is using arguments, and that's what we're going to touch on in the next lecture. Soc. There 31. Simple arguments: Hey, already welcome back to code dynamic websites with PHP. This lecture is called simple arguments and in this video, we're going to continue from where we left off in our previous lecture, which was custom functions. And in this video, we're going to learn a little bit more about PHP arguments within our functions. So hang in there and let's do this in your code Dynamic Websites Course files folder. We are in 25 simple arguments in your code editor. Make sure to open the final and practiced up PHP files in the 25 simple Arguments folder. Practice up. PHP is a sandbox we're going to use to build what is in final dot PHP bottled up PHP Looks like this. We have an example here where we're using one argument and an example where we're using two arguments. Obviously, you can't see that on the front end of our Web page here, but PHP is doing that in the background. So why don't we jump into our lecture and learn a little bit about our PHP arguments? Functions can be incredibly powerful because you can program them to do almost anything you want them to one important step in making your functions even smarter is to use arguments within your function, not the type of argument where you and a friend are bickering about a disagreement or something like that. I'm talking about arguments within functions, two very different things. Think of an argument like a variable. Your program can pass extra information to your functions using arguments. You specify your arguments within the parentheses after your function name, and you can have as many as you want as long as they're comma separated. So let's take a look at example of a function with a single argument. So here we have our PHP script. What we're doing in the above example right here is we're passing an argument to the hang 10 function. You can see it right here. It looks like a variable. It has the dollar sign and then a name. So this is an argument. Later in our script, we call our function several times with a string of text within each parentheses. So here we have hang 10 Hawaii. Hang 10 California, hang 10 Newfoundland, and each time we call our function with a new argument value. That value will display on this on the screen, along with the text, we provided Inter function here, So inter function were saying Echo were surfing in. So this is going to stay static each time we call our function. But what's gonna change is the variable right here, which is the argument within our hang 10 function. So it's gonna look like this. We're surfing in Hawaii, were serving in California, and we're surfing in Newfoundland. So let's look at an example with two arguments. So in our PHP script here, all we did was add another argument, separated by comma. Then when we called our multiply together function. Later in the script we provided to values to take the place of our vow one and Val two arguments within our multiply together function. We have a variable, and we're multiplying. Val one and Val, two together, storing it in the product variable then were echoing this text. The product of the two numbers is and then were spitting out the product variable, which is actually the product of Vow one and Val to multiply together. So when we call multiply together, we can choose which numbers. We want them to multiply together by providing the two values of the arguments. So the result in this case, 378 This is dynamic, So why don't we jump into our code editor and see what we can do here we are in practice that PHP. Make sure to change your name in the custom variable and let's jump into our one argument PHP script. Start by building a function and let's call it Harrington. And in here we're gonna add our argument, and that's gonna be location and down here. Let's echo. Some texts were surfing in and then location. Put a brake tank after that, maybe an exclamation point to to make it exciting. There we go. So that is our function with our argument. Very simple. Now all we need to do is call our function right here. You could see that coda to already knows that there's an argument that I need to fill in here so you could see when I'm typing. Hang 10. It pulls it up as a function that has been initiated within my script. Pretty cool. It helps me code faster. So if you're not using coda to, I strongly suggest you try it out because it speeds air coating up quite a bit. You can find it in my resources section on my website at Brad House did not see a slash resources, but anyway, you could see here hang 10 and location. So I need to fill in that value for that argument. It's asking me, what do you want to put here? So I'm gonna say Hawaii. And then I was gonna copy and paste that two more times and change the value of this argument. Come more times. California good surf spot and Newfoundland. Very underrated, sir. Spot. Very cold. Okay. And so let's say that and check it out in our practice that PHP. What page? Here it is. One argument. We're surfing in Hawaii, California and Newfoundland. So there we go. That is a simple example of how to use one argument. Let's jump in and try out two arguments. So we're going to start by building our custom function. We're gonna call it, multiply together, and then in here, we're gonna add to arguments Bowel, one comma, separated, vow to and then we're gonna inside the functions, Say, store the product of al one and vowed to in the variable called Product. So that will multiply these two values together in a variable called product and down below that we're gonna echo some text and say the product of the two numbers is and then product . And there we go, Close that up with the semi colon and down here we're gonna call our function, multiply together. You could see Koda is looking for two values here. So I'm going to say the 1st 1 is 14 and the 2nd 1 is 27. You can have them be whatever numbers you want. If you curious to see some crazy numbers multiply together totally up to you, pH people do it all for you. Say that. Check it out. The product of the two numbers is 378. Awesome. So there we go there. We have it too. Good. Solid examples of how to use arguments within your custom functions. The sky's the limit here. Maybe you have some cool ideas. Feel free to try it out here in the sandbox. Totally up to you. And I will see you in the next lecture where we're gonna be finally jumping in tow, building an actual dynamic website with PHP, with everything we've learned. See? There 32. The final website you'll build: Hey, already welcome back to code dynamic websites with PHP. This lecture is called Final Website, and in this video we're going to be running through the final PHP Web site that you're going to build using the skills and knowledge that you've learned throughout the entire course. So let's jump right in in your code. Dynamic Websites Course Files folder. We are in 26 Final and you'll see two folders in here when called Instructor and one called Student. The Instructor folder is Thief Final Final site. This is the fully built site that I've going to be using as the example and that you can use for reference throughout the development of your version of the site. And the student folder is just an empty folder that has one folder within it with a set of images, so you don't have to worry about exporting those cause. That's not really what this course is about. So in the Instructor folder, if you open index dot PHP in your browser, then you'll be able to see the final site, and this is what it looks like here it is Franklin's Fine dining, a site that I designed and coded myself. So it's a very simple site. Ah, and it's not the most out of this world design or anything like that. But it covers all the essentials that we've been learning throughout our PHP course. And, believe it or not, the site is fully dynamic using PHP and utilizes all the essentials that you're going to use for your future dynamic websites such as global headers, footers, dynamic hours, uh, query strings to pull up ah, template and then populate it with an array of ah info. So we'll get into all that. But I'll show you. But the site looks like So here's the home page. We just have some static text. But what's special about this is we have a global header, which means we only have to code the header once, and it displays across all of the pages. No matter how many pages you create, and the benefit of that is, say, you have 30 pages on your website and you need to make a change to the header in the knave bar. Say, for example, then you don't want to have to change that 30 times, whereas if you use a global PHP header. You change it once and it's global across the entire site saves a lot of time and it's something that you should be really excited about. And in the footer here we have some basic information. But what's special about this is we're using a PHP plug in that somebody has already developed to see if our if we're open today or were closed today, so you could see, for example, for me it is 10 in the morning on a Tuesday. So are are. Restaurant isn't open until 1 p.m. So it says we're closed. Today's hours are 1 to 9, so I'll show you how to do that a little bit later. We have our team page where we have our team members and we have three of them here and their information is being pulled in dynamically with PHP. We have a menu page where we have four simple items here, and each of these items is a link, which opens up a template called dish dot PHP. So I've only coated one dish dot PHP template, but it's populating based on the link were clicking the info for each of their respective items in the menu, so club sandwich pulls up dish dot PHP and it's looking for club sandwich, and it pulls the info for club sandwich. A suggested beverage, he suggested. Tip the price and the title. And if you go back to the menu, click on a different one and it pulls up that info. So something really neat about PHP using templates and then we have the contact page, something that a lot of people been requesting is how to create a contact form that actually submits an email. So here we have your name or email in a message and then a check box to subscribe to a newsletter and then send a message. And that's what that does. It sends an email to the recipient here that is defined in our PHP, and they should receive an email in their inbox. So why don't we jump right in? Hey, already welcome back to code dynamic websites with PHP, and before we move on, I have a quick favor to ask you. I've dedicated thousands of hours to creating great content for my students, and the reason I can reach so many people at this point is because of people like you. This course alone has taken me months to create. And I'm not asking you to pay anything for it. All I ask of you is one little thing. If you're checking out my course from YouTube, I would love if you could share this course with your friends, family and work colleagues. And if you're checking this course so from you to me, I would especially appreciate if you could give me a quick rating and review using the star rating and the review box. You can leave me an honest review and you can always change it later. Should you have a different opinion? By the end of the course, you're awesome. Scene the next video. 33. Final: Basic layout: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called Code a basic Web page layout, and in this video, we're gonna do exactly that and just start coating some simple HTML and then further on down the road in some upcoming lectures were gonna be splitting the html out into separate PHP chunks. And we'll get into that a little later. But why don't we jump right in in your code? Dynamic Websites course files folder were in 26 Final and we're gonna be working with the student folder. So, in our code editor, let's start off by opening the 26 Final folder and make sure you have the student file. It's the student folder open, because that's it we're gonna use to create our final site. I have the instructor folder here for reference and feel free to use that as we're going through, just to make sure you have everything working. But for now, we're not actually gonna be mimicking what's in the Instructor folder because we're gonna just start with some basic HTML. So first things first in the student folder create a new file and call it index dot PHP. That is her first PHP page. Let's work with that and code a basic HTML skeleton. So first we have the HTML five doc type, and then the next part is the HTML tags with in HTML tags. We have head Tex after the head tag. We have a body tag where we put our HTML and then in the head tag, remember to put the title and then we're going to be linking our style sheets. So I've already done all the styles. This isn't really a course about CSS, so we're just gonna link that up. So used the link tag here. H ref, we're gonna be referencing the assets folder in the root of the course files folder. So that is forward slash assets styles, not CSS and then rail style sheet. All right, that'll tell her html to look for that style sheet, All right, And next up we are going to at a couple more tags and some ideas and classes so that we could start working with those a little later. So let's give the body the idea. Final dash example. That's so the CSS kin style our Web page inside the body tag. Let's add a diff give it the class of Rapper. I like ending the Div with a comment just so let myself know where that DIV ends inside the rapper. We're going to have a div with the i. D. Of banner and I'm gonna close that here with the comment. After that, we have a div. We're gonna give that the I d of knave and then after knave, we have another death. Let's give it the class of content, all right, and then within content. Let's add at the end here a div Give it the I d of footer We're gonna add what class to this called CF. And basically we're just adding this because in the styles I have a class called CF, which stands for clear fix because we need toe access the clear fixed class in the CSS in order to clear the footer I. D. Div because we have a couple elements in here that will be floating. And like I mentioned, this isn't really a course about how to design or style a website using CSS. I have some courses for that. This is mainly about PHP, so I'm just going to you. Add the skeleton here with all of the pre defined ideas and classes, and that's gonna be referenced in the styles that CSS file in the Assets folder. If you want to check that out and just see what I have coated in the CSS folder totally up to you, you can go in there and check it out and see what I'm doing and why I'm doing it. You could even feel free to change it up and make the site look a little bit more like your own. So let's continue inside the footer. We have a diff We're gonna give it the class of Colin because we have a CSS class called Column where we are going to be floating some dibs within the footer and we're gonna say three because this is a three column footer and I'm gonna copy that and paste it two more times. But on the last one, we're actually going to give it additional class called last, because in the CSS, I'm using the CSS class of last to remove the margin. Feel free to check that out if you want to know more about it. All right. In the column here, The 1st 1 we're gonna add a strong tag, and then we're just gonna put the text phone and then 808 5 to 93819 This is just totally fake number. Or maybe not. I bet you if you call that number, it would probably called somebody's house or a business in Hawaii. But I don't know. You could. You could do whatever phone number you want. I just picked that rent at random. All right. In the second column is that another strong tag? The text of location. 123 Cappio, Lanny Boulevard Break tag. Honolulu, Hawaii. One of the chances that this number actually goes to 1 to 3 Kathy Lanny Boulevard in Honolulu. Probably very slim. All right. And then the last one. We're going to add a little bit more text here, so let's give some space a strong tag and let's say hours M tag for emphasis. Tuesday, too. Thursday break tag one o'clock PM to nine o'clock PM to break tags to get a little more space. And why don't we just copy this so you don't have to cut all the same mark up again. And let's say Friday to Saturday we have 4 p.m. 2:11 p.m. and then paced one more time. And let's say Sunday, Monday and let's just say it's closed and only one break tag at the end. Well, let's leave too. Okay? And all right, so after our footer, let's add a small tag and let's say copyright. That's the copyright html Entity 2014. We're gonna make it static right now cause later will make it dynamic of PHP. Brad Husi. You can add something else a little later, we're gonna use PHP to dynamically add that. All right. And then after the rapper Let's go, Div, let's give it the class of copyright info. Was that up here and in here? We're actually going to Let's just add a little bit of PHP right now. PHP include this is the PHP include function, and we're going to include something in the Assets folder and then the includes folder within the assets and a page called Copyright Up each beat something that I created so that it has my copyright information at the bottom just so people know that this is the course that I created so they don't try and steal my stuff. All right, so dot, dot, slash throwing up a folder assets includes and copyright dot PHP. All right, so if we save this and we check the index PHP file out in our browser, let's see what it looks like. All right, so we have something here. We're kind of missing a few things like the the logo and everything like that. But we have some stuff, So why don't we just clean up that header just a little bit? Alright. So back up here in the banner, let's add a logo. So a h ref and we're going to just link that back to the root folder and say, Title return to home, All right, And then an image tag. The source will be image boulder that we have in our student folder here and then bannered up PNG. And let's add some all text. Franklin's fine dining say that and you should have that now in your page. There we go. There's the banner. So now we're just missing the navigation bar. So let's add the navigation bar all right here in our novels at an unaltered list and then l I tag in the L A tag. Let's put it a tag. All right, in here. Let's start with home. And let's give that the index that PHP file. Copy this. I'm gonna pace it three more times. Number is gonna change the info. So we have a team, then we have menu and contact. Let's change the pages. Although we don't have them yet, we will change them now so we don't have to later menu and then contact. Now, keep in mind right now, this is static. We're actually gonna be using PHP array and loop through our array to dynamically generate our list items. But for now, this is what we're gonna do. Let's check that out and see what it looks like. All right, here we go. So now we have a good basic layout. Thes don't go any right now. In fact, if you click them thesis, I will break and everything is static. This is a fully static HTML page, except for this part down here. But other than that, we have a static html page, and that is our basic Web page layout. And in the next lecture and the following ones. After that, we're gonna be picking this thing apart and creating a dynamic version of this, so I'll see there. 34. Final: Global header & footer: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called to template ing a global header and footer. And in this video we're going to be taking our static HTML Web page that we just coat it up in the previous lecture and taking the header and a footer out and splitting them into their own global header and footer PHP file so that we can use them globally across our website, no matter how large are upset grows so that we don't have to keep editing the header and a footer if we make changes on any those pages. So let's jump right in. All right, so here in our code editor in our student folder, we last left off with her index up PHP file and that had everything in our basic Web page layout. So from the dock type, we had her html all the way down to our footer and we closed up the HTML tag. This is just a static index step PHP file, but we want him utilize our skills and PHP and try and take advantage of what PHP can offer us to make our website more dynamic and easier to maintain. So we're gonna be splitting out the header and a footer. And I don't just mean the head tag. Or, you know, if we had a div with the idea of header or the did with the idea footer, I mean the header and footer PHP files. They're gonna be templates. And they could be any section of the PHP file here that we want any section of the HTML and we're basically going to be taking everything from line one. So, Doc type all the way down to the opening content tag. We're gonna take that, remove it from index up PHP and paste it in a separate header dot PHP template. So why don't we just do that? So let's take this out. Cut that. Just go. Command X for cut. If you're using a Mac, I'm not sure what it is on PC, but you can also go edit cut so it copies it to your clipboard and removes it from the file and in your student boulder at a new folder and call it includes in the includes folder. Add a new file and call it header dot PHP. Open up your header PHP file and paste What you just cut from the index dot PHP file. So here we have our header. So save that And back in your index PHP file, you'll see that you no longer have a header section. Ah, and now we're actually gonna dio is create a new file inner includes and call it footer, not PHP. All right. And in our footer dot PHP, we're basically going to take everything else that was in the index dot PHP file. So all of this cut that. And now we have nothing left in her index up each people. It's kind of funny. We did all that work and index that PHP Now it's all gone, but it's actually good because now, if you paste the contents of your clipboard into footed up PHP, we now have a header dot PHP and a footer that PHP. But the content that was once in index dot PHP and we're actually going to, uh, utilize a little bit more includes here and templates within the header and footer while we are doing this lecture. So let's go back to header Now, Remember when I said that the, uh, knave is static, but we're actually gonna be using PHP to make it a little bit more dynamic. Well, why don't we just do that right now? We're in here and are headed up each piece. Create a new file includes Call it now that PHP cut the all the list items out of here and replace inside the in order list a PHP tag our script and say include includes slash nab dot PHP. They're gonna be including nabbed up each piece. So basically, this is just going to pull this template right here in our HTML. So inner headed up PHP. We're going to grab what is in includes and knave dot PHP currently nabbed. A PHP doesn't have anything in it, but it will now just a quick note. You might be wondering, why am I saying Look for the includes folder and then knave rather than just saying Navid a Petri because header dot PHP is in the includes folder. So shouldn't you just say include peach be include nabbed a peach because it's literally in the same folder? Well, not necessarily, because what we're actually to do in a little bit here is in the index file. include the header dot PHP template and index is in the root of our final website folder, which means Header will therefore be in the root. So that means this includes script here. We need to dive into the includes folder because we are now going to be in the route of the folder. Hopefully, that makes sense. So open up your nabbed a PHP file. It should be empty, But let's just paste our HTML for now. We actually won't be using this HTML at all, but I want to use it for reference so we don't have to go back and forth. Let's start by adding an UN ordered list. And that just reminds me that we actually need to remove the honored list in our headed up PHP. And actually just have the PHP include script inside the Knave Div. Just that because we're gonna use the UL end. The include Naveda PHP file. Let's go back. All right. In our honor list, let's just paste these bad boys The list items in our on ordered list. So, technically, now in our header dot PHP file, we're pulling the nabbed A PHP, uh, list items right here. in our nav tay and it should have all of these list items that we just paste it in here. So why don't we see what everything was fixed so far? But before we do, we need to go back to our index PHP file because there's nothing in it. If we were to navigate to index dot PHP right now, nothing would show up because there's nothing in the index folder. We've done a lot of work over here, and they had her Footer and Navid A PHP, but we're not calling it at all. We're not asking PHP to pull that influence. So let's do that. All you need to do is at a PHP script here in your index PHP file and ad, and include to look for header dot PHP and then at the bottom were actually going to the same thing. So I'm gonna piece the separate instance of this Petri script because we're actually gonna have some html in between the two right here. So it's replaced this with footer dot PHP. Now save this. Open up your index while you'll see it hasn't changed on the front side of it. But that's a good thing because we actually have our header and a footer showing up right here in the index dot PHP file. But now we're using templates. If you were to look at the source code, it should basically look identical to the original index up PHP file. Because the browser doesn't interpret PHP as the PHP that you see in your code editor, it actually spits it out as HTML. So here's your index PHP file all in one nice formatted file, and that's how the browser sees it. That's why you see this. So let's take this a step further, and we're going to make our knave a little bit more dynamic using PHP to make it a little bit easier to maintain your site in the future. So we're actually gonna add another file to her includes folder and let's call it a raise that PHP. And in there is where we're gonna add a bunch of PHP arrays throughout the court, the development of our final site. So go ahead and open up your raise. A PHP file started off with a PHP script and let's start by adding some navigation menu items using an array so now menu items. Let's call this knave items and array and within the array, Let's at another Ray or a series of a raise is what we're actually doing. And let's, um, ad slug. And then this will be called index dot PHP will be the slug, and then title will be home. So the key and the value pair it's copy and paste this three more times. Just change the values so this will be teamed up PHP This will be team and then menu dot PHP menu and then contact up PHP and the title of the contact. Save that in our arrays a PHP Now in our knave dot PHP file, we're just going to use a simple PHP for each loop. So PHP and for each never items as item echo. And here we will add some html and then ah h ref, we're gonna need to use some backslash is here to escape these double quotes. If you remember in a previous lecture item slug is what we're looking for. So that will give us thesis slug, meaning the file name so index dot PHP teamed up each be so and so forth and then item title. And that should give us basically what's gonna look through a knave items and give us thesis lug and the title of each of the elements in our nav items array. And that should spit out our list items. But we won't actually get to see our list items because we're not pulling in our, um, a raise folder. There's no way that, you know the now that PHP file can. No, what is in the arrays? A PHP? Because there's no reference on our in our website yet. So here at the top of our headed up huge P, this is a really great place to put some PHP one a load first thing. So PHP script. Let's add an include folder or include function and say includes raise that PHP and that should be all you need to do. So why don't we check it out now in a browser? So they're the home team menu and contact looks like it did before, but now it's actually being pulled in baia a PHP array, and now all you technically need to do in your erase file is just add another array or another Siris of a raise with a slug in the title. You wanted to add more pages. Okay, so let's just make sure we have everything here. We have our dynamic header and our dynamic footer, and I believe that we should be good to go. So that is the header in the footer templates we threw in some raised a PHP and Anabta PHP . So we actually kind of jumped right in here and got her hands really dirty with some PHP template ing. Hopefully that made sense. Feel free to rewind and start the whole lecture over again. Or just go to the specific parts that you need to, uh, learn again. And I'll see in the next lecture where we're gonna be diving even deeper into this PHP awesomeness. See there. 35. Final: Copyright hours: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called dynamic copyright and hours of operation. And in this video, we're gonna go through and add the copyright information to the bottom of our footer. But it's going to be dynamic, so it's gonna know the current year. So it's always up to date and the hours of operation. We're going to install a PHP plug in that will determine if our store is open or closed. So let's jump right in. All right, So in your code, editor, make sure you open the footer dot PHP file in your includes folder within the student folder and your foot or dot PHP file. This is where we added off the footer information. So the phone number, the location, our hours of operation and the copyright information plus the closing body in html tags. Currently, this is all static. So we're not actually using the utilizing PHP to make our footer a bit more dynamic. And so that's what we're gonna do here. So let's start with the the easiest part, which is making the ah the date copyright date dynamic. So all you really need to do here? We've done this a whole bunch in throat, the entire course. So you might have already You might already know how to do this, and you've already done it. But this is how you do it. So let's remove the 2014 and PHP Echo date the date function. And then as a parameter report, why in that squint capital, why, that's gonna give you the full year. So 2000 and 14 Currently, it's 2014. All right. And here what we're going to do is we're going to do something. Ah, little bit more fun. We're gonna PHP echo a variable called company name. Now, I don't believe we actually have this variable created yet, So let's go to our header dot PHP file and up here at the very top in our PHP script right above the include let's add the variable company name and the value of the company. The invariable will be Franklin's fine dining because that is what this fictional restaurant is called. Save that and then go back to your footer dot PHP. And now this company named Rabel should actually be valid, and your footer will have a dynamic year and, ah, dynamic variable, which is the restaurant name. So let's check that out. All right, so Copyright 2014 Franklin's fine dining perfect. So that's actually working. This is the current year. If you're from the future and you're looking at this and say 2015 then this will say 2015. If it's done correctly and Franklin's fine dining is the variable. If you change the very well, obviously this will change. So let's move on and do something here with the hours of operation. So back in her code editor, what we're gonna do is we're actually going to leave the hours here static because this this is what it is. But the special part is, we're going to insult a PHP script or plug in that will determine if the stores open or closed, based on the hours of operation that we, uh, set as parameters within the plug it. So first thing you're gonna need to do is go to a specific website. You are l get have dot com slash Corey ETS korn slash PHP store hours. You'll see a page. It looks like this, and all you need to do is click on download zip. And what that will do is download the zip file with all of these files in it. So the read me indexes store hours, So I will open that folder up in my finder and it is a zip file. I'm going to unzip it. And here is the folder. All I really need is thestreet or hours that PHP file because the index is just the example to read me is just if you want to go through it to see how you use it, which you totally can, and the store hours is the plug in itself. So take the store hours and drag it. If you're using a Mac to your quote editor and drop it in your includes folder. So store hours, I'll show you what it looks like. So here's the store hours plug in, and it has a bunch of PHP, and all we really need to edit is what it actually says here from online nine. Ah, there's a comment that says edit following section only. And then somewhere down here it will say and editing. So you don't need to touch any of this stuff down here. In fact, it's not recommended. Everything here is what you can play with. But before we get into that, we need to do something. Uh, you need to go back to your footer dot PHP file and under the Let's say the Sunday to Monday text here at the very bottom. I'm going to PHP include the includes folder store dash hours that PHP so that's going to call PHP is gonna call or include that file within this section right here. So it's actually gonna take the contents of that Petri script and insert it right here. Now the contents of the script go back to store hours. It looks like there's a lot here, but it's actually going to spit out something very simple. So there's a lot of work that went into this just to show you one simple each team l line. So when I include this in my footer dot PHP includes store hours, it's going to include the line that the store hours script will echo. But in order for that to echo the right line, need to go in and configure our store hours, plugging circle back to store hours. Let's start editing. Okay, so the first things first is you need to set your default time zone and you can go to the soil right here. PHP dot net slash manual slash e en for english slash time zones up PHP and will give you a list of all of the pre defined time zones, and then you can choose your time zone. So for me, the closest time zone were the times on the Peach people. Let me use his America slash Edenton. Okay, so I've said that now defined the daily open hours must be in 24 hour format, separated by a dash if you're closed for the day, set to all zeros in this syntax if open multiple times on Monday. El to enter the time Rangers separated by comma open late, for example, six PM to one AM add hours after midnight to the next day, for example, like this now we won't be using too much of this. Our hours of operation are actually quite simple, but let's ah, let's go ahead and start changing our hours array toe work for us. Okay, so we have ah, right here. Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. Let's start with Monday. Now let's take a quick look at our hours. Okay? So it looks like Sunday. Monday we're closed. So, like it set up in the description right here. If we're closed, we need to set to all zeros. So 00 colon zero zero dash 00 colon users who were closed on Monday and we're also closed on Sunday. So let's just copy that and paste it down here in the Sunday array. Okay, Now, Tuesday, we're open from I believe it was one until 9 p.m. My right. Yes. So Tuesday to Thursday. That's the case. So 24 hour format, one o'clock is 13 100 and nine would be 2100 and we don't need to separate by comma because there's only one timeframe in the day that will be needing to be open. So now let's copy that and actually paste it all the way to Thursday. Now we change here on Friday from four o'clock to 11 o'clock, right? Yes. So four o'clock is 1600 and 11. Oclock is 2300. Saturday is the same time we're open Friday center at the same time. And paste that and there We should be good to go now. If you go down, there's an optional section you can adhere. So optional. Add exceptions for holidays, and things like that works best with the format. Day slash month Leave array empty if there are no exceptions, So this would be if your store is closed. Say, Christmas Day, Christmas Eve, New Year's Day. You know, if you have specific days that your company or your store restaurant, whatever it is takes off. This is where you would add that, and we'll actually say 12 25 because that is Christmas Day. Ah, and then New Year's Day. Let's be closed as well, and it's already set to 11 January 1st. Perfect. So that should be it for that. Now let's go down. And the last section here we have the HTML output. This is the line that will show in the browser. So ah, you can read the rest of this year to see what kind of syntax and everything you can use for this output. But this is what it looks like. So open now, The very well open. Now this is the text it will show closed. Now, this is the text closed all day, an exception. So this will spit out all of the appropriate text based on the hours of the day and the times of the year that you were open and closed. Time for Matt. You don't necessarily need toe change this, but if you want to, you can go to the PHP date function page to see the options that you want to list the time . If you want it to be specific about how you want the time to display down, here is the day Short code. Ah, and this used up here you could see percent day percent. This is the how the days are used. So it's an array Monday all the way through Sunday, and you could type out in the value of the array how you want the specific dates to be displayed. So I would like them to display as Mondays, Tuesdays, Wednesdays, Thursdays, Fridays and Saturdays. Because this is what's gonna show up here in our HTML output. And so really, that's it. That's basically how that plug and work. So if I save that and now let's go back to our example, refresh it and you'll see some text pop up here. So sorry we're closed. Today's hours are one until nine. Obviously, this looks disgusting because something is happening at the HTML that's being spit out. Doesn't have the correct style, so we can go back and fix that pretty easily. Um, one thing I forgot was here in the HTML open. I don't actually want Level three headings. I want them to be strong tags, and I added a class to the CSS for open and closed texts. So when it's open, it will be green, warmer clothes that will be read. So change all of your age threes too strong. He's gonna go through and do that right now. Its three strong looks like this here. Didn't have a closing tags to make sure to add that. Strong, strong, so strong, very strong. Cool. One last thing. Let's add some classes, too. The strong tag. So for open gonna add the class open. And be sure to use single quotation marks here because we're currently within double quotation marks and we don't want to cancel them out. So class open for the open. Ah hmm. I hope it class closed for the closed age tomorrow, put looks like that's all the rest of them. So add that to the strong take. See that? Now go back to your website. Here we go. So for me, it is a Wednesday at 12:45 p.m. Which means we should be open from 1 to 9. So currently says, Sorry, we're closed cities hours or one until 91 It is one o'clock until nine today. For me. Ah, the This will be green and will say Yes, we're open to these hours are one until nine. So that's how the PHP plugging works and there are many Petri plug ins out there. So if you don't want to build something yourself, sometimes it's too hard or it's out of your skill level or you just want to reinvent the wheel and somebody's already done it really good. There's a lot of really good PHP developers out there, and there's a lot of open source plug ins. That means they're free. People work on them all the time, so you can you can ah, come up with really cool things like this without having to do too much. Work yourself if it's already been done really well. So that's what we did here. And hopefully that made sense. If not, you could go back and check out the lecture again. Otherwise I'll see in the next lecture. See there. 36. Final: Team members: Ola. Everybody, welcome back to code dynamic websites with PHP. This lecture is called code a team member array and template. And basically, we're going to do in this video is create a PHP array with ah few team members and their information within the array. And then we're gonna coda ph B template that will pull the information out of that array and display each of the team members. All right, let's jump right in. All right, so in your code editor first thing, I want you to do IHS create a new file called team dot PHP in your student folder. So in the root of your Web site, So new file team that PHP Make sure that's in your student folder. There we go and open the team that PHP file Nice and empty blank slate. Let's get started. So lets out a PHP script. Inside are PHP script. Oh my goodness gracious. There we go. Let's do a couple things. Let's include our header dot PHP, something we're gonna want to do for every one of our templates. If we keep creating templates on our Web page or website and something that you will commonly do in most if not all, of your PHP Web sites because we have the header dot PHP that has all of the the important information, like the doc type in the opening and closing tags and everything like that. We need to include that in our templates. So on our team that PHP template, we need to make sure you include that. Something I want to also do that we haven't done yet is show you. Consider this a little mini bonus lecture within this lecture. Basically, I want to have the title of the Web page be dynamic based on the page that were on. And what I mean is the title of the webpage literally so appear you could just see in our browser tab. All it says is local host 8888 and then the rest of the directory. I don't actually want that. I wanted to be the title of the Web page, and you can do that in the hitter dot PHP by just adding your text here in the title tag. But then it's just static. Every time we include the header within her templates, the title will always be whatever we put in the title take. So if I go to team menu contact, if I have more pages, if it's hard coated in the title that I'm always gonna have the same title in the browser tab. But with PHP, we could make it dynamic. So check this out. What we're gonna do is in our teamed up PHP page above the include that we include the header because we want this toe happen before we include the PHP header. We're gonna define a constant. Remember that mystery? A good use of howdy to use a constant in real practice So defined title and this page is gonna be called Team and then pipe Franklin's fine dining. So this is going to be the constant called title. Now all we need to do Let's go to our header and do this one time. So in our title PHP Echo title, that's it. So every template that we create after this, as long as we define the constant title and give it the name of that page, the title of the Web page of Iran will always be the one that you're on because you defined it in a constant and the title is dynamics of Check this out. All right, so I just realized a couple things. The title tab of here, The tab up here in the browser. It just says title. The reason why is because we're on the index file index dot PHP. We didn't define a constant. So it's gonna be empty in just echo literally the text title or give you an error. I also realized one other thing. The home page doesn't have any content on it. Simple mistake on my part. But good thing you're still with me, because we can do it right now before we do anything else, it will take probably about 30 seconds. Probably less. Okay, go to your index dot PHP file and you could see here. We just have to Ph b includes the header and footer. We don't actually have content on our home page. Simple enough. Let's just add a div. Give it the I d of Phil Los o phy. There we go. End that here with a comment in here. I'm gonna put a horizontal rule and another one at the bottom. And then in between here, I'm gonna put a level one heading and say, Franklin's they'll loss ho fee Uh, fine dining under their paragraph tag and I have some text lined up here in my clipboard. You can feel free to copy. Ah, what I'm pasting here, literally. You can't copy and paste what I'm copying, basting, but you could type it out. Or just use Lauren Epsom here it Franklin's. We know that good food isn't just about how expensive the dishes were. Not pompous. We're proud. We're proud of our worker quality, our environment and our love of for food and family. And then the last paragraph tag here, I'm going to say, Oh, and you can call us Frankie's your family here. Stereotypical restaurant text. Cool eso there We have our philosophy on our home page. Save it, check out the home page. Boom there it ISS already looks nice, but we still have our title issue appear simple. Fix in our index a PHP to find a constant to fine. The title title will be home pipe Franklin's Fine dining and there's a constant Save it. Check that out home. Franklin's fine dining there it iss now for good or teamed up PHP page, which should be right here. Just click on this tab we've already added are in our array that slug, so it should go to team a PHP. Here's team you could see appeared, says Team. Awesome. Let's go back to our team template and let's start coding some P h p. All right, let's not forget toe include our footer There we go and little type over here. Perfect. So in between these PHP tags, let's add a div Give that did the idea of teen Dash members and the class of CF, which stands for clear fix because I have a CF class in my styles which clears this Div because we have some floated elements within it, not a big deal. If you care about what that is, then you could just go to the Assets folder and the root of this code Endemic Websites course files folder and check out this styles otherwise moving on. All right, here we have our team members Div, it's ah, level one heading our team at praying Cleanse Cool. I have some text lined up here. Feel free to type it out or just use some Laura MIPs. Um we're small, but mighty Franklin's fine dining has a family owned, has been a family owned run business since the dirty thirties, and we're proud of it. When you get these three together, you never know what can happen. But you can count on one thing. The best food you've ever had ever mighty bold claim, all right, and then ah ah, horizontal rule after that because I used some CSS to make the horizontal rules look pretty . So let's save that. And let's see, we got so far our team of Franklin's. We got the text here and then our sexy little horizontal rule. After that, we need to add the three ah, headshots of the the team members and their bios and all that sort of stuff. But the first thing we need to actually do is create the array for the team member because this is gonna be dynamic, remember? So go ahead, open your a raised up PHP file right now, you'll see that we have on Lee the knave items. What we're gonna add the team members in here. So go ahead and an under here. Make some space for team members. Let's add our team members array a Ray. Here we go. Perfect In here. Let's do some magic. All right? We're gonna need toe ad another array in here because, ah, we're gonna add some team members. All right, here is the skeleton for the array. We need to add a name and that it will be the first guy will be Frankie the third. And then after that, we need to add a position. And that will be owner separated by comma. Another key value pair Bio. Frankie is the great grand son of the original Franklin. He is the owner of Franklin's Fine dining. He cooks a mean free Chatah. All right, Miss Frankie's bio and now image we're gonna reference. Ah, what? The file name is without the extension because I've already lined up a bunch of images and your image folder. You could see Francis, Frankie and Carlos are. The three team members were gonna reference the name and not the extension, because, uh, the HTML template will do the rest. We'll get to that. So, Frankie lips in a string. Frankie Perfect. So there is our first team member Copy that we've had already already done all the work and paste it again, actually, one more time. And here we will add the other two team members. So, Francis, the general manager, and we have some text here for the bio for Francis Francis knows her stuff. The big sister of Frankie himself. She runs the show. Don't miss her margarita Mondays. And then her image name is Francis. And then we have one more guy. And that would be Carlos, who is the head chef? His bio. Carlos is the epitome of the phrase. Don't judge a book by its cover thes html Entities are the left. Double quotes, right? Double quotes the em dash. And then you simply cannot find a better chef. His image name is Carlos. All right, save that head back to your team template. All right, in your team template, let's get dirty with some PHP and let's do a for each loop for each. We have team members remember the team members array we just created and the reason why the team deputy P file can access the arrays. That Petri file is because in our header that PHP which is included right here we include our arrays dot PHP within our includes folder. So It's all interconnected like a big Web team members as member. All right. And then we're actually gonna close the PHP tag just like that, because we can now write some HTML right here. But we have to make sure to close this for each loop. So let's add another PHP tag or script. The closing curly bracket there. And now in here, we can actually write HTML. So we're no longer in the PHP tags. But PHP knows that there's an opening curly brace here. So anything after that is going to be, Ah, because of what's in this for each loop. And then we close the for each loop down here. Okay, so Div class member member Okay, so inside the member class div, we're gonna add an image, and the source will be image slash. This is where we start accessing our for each loop again. So PHP Echo member and then image Remember the key, um, in our arrays file is image and that will give us the name of the image so close. This PHP script here dot PNG Ault Very important. PHP Echo member name. The reason I did this is because the all tags should have something descriptive in the image tag. So member name is actually get the name of whatever team member we're looking at. And then right here, we're echoing the member image, which is the slug without the extension. So we are going to be pulling each of the team members using this pH B snippet here and here. So that will give us our image. A level two heading PHP Echo Member name again. That will give us her name. We're gonna get a paragraph tag here and then PHP Echo member and then bio. Okay, so that is basically Well, if I had one more thing down here after team members, just one at a level. Sorry. Horizontal rule just below there. But this is it. So that's all we need to do. We don't need to code three team members. We don't need to code this three times. I don't need to copy and paste is three times and then hard code. Each of the members names, bios and images because PHP for each loop will do that. So I opened her for each loop right here said for each team members as member, so PHP is gonna loop through our team members array and individually give us the information for each of those are raised within that array. And so each time it loops through, it's going to help put this bit of HTML. So it's gonna output a David the class of member, an image with its respective image slug and its respective ah name. And then same here is gonna get the name of the member were currently looping through and the bio of the member we're currently looping through. And it will do that until the array is complete. So because of this, check this out. We have our three beautiful team members Frankie Francis and Carlos, with their their names and their bios all because of PHP. So that's pretty cool. Ah, and that's it for the team template. And next up, we're actually gonna be moving a little bit further in and, uh, getting her hands dirtier and a bit more. Uh, we're gonna be a bit more advanced with our pH. Peeing so we'll see there 37. Final: Menu: Hey, already welcome back to code dynamic websites with PHP. This lecture is called code A menu array and template. And in this video, we're going to be creating a couple of PHP pages and we're gonna be populating it with some dynamic menu items. And we're going to use PHP arrays to create some menu items that we're gonna be pulling from in our menu templates. All right, let's do this. Okay, So first off, I want to show you what the final website looks like in particular the menu section so that you know what we're gonna be building as we're doing some PHP and everything like that. I want you to have some context in a visual image in your head of what you're actually gonna be building. So here's the menu dot PHP page. It has a basic overview of our four menu items that we're gonna be creating. And each of these menu items are link, and they go to their own separate pages. But in fact, they're all using the same page, which is called dish dot PHP and dished up pH. B is a template where will be using some PHP to pull in the info from an array for each of these respective menu items so far to click on Club Sandwich. I will get info about club sandwich notice here that I'm in the dish dot PHP template and then I have a question mark item equals club sandwich that's gonna pull in the club sandwich information into the dish, not PHP template and display it here on the page. If I go back and I choose a different item like Mexican barbacoa, I have the same dish, not PHP template. So same layout, but new information. And that's a really huge part of using PHP to program dynamic websites. So, for example, Facebook has millions of users, and each of those users have a profile page. But Facebook isn't going to code millions of profile pages individually. They'll just code a profile template and then pulling the information depending on who's logged in so they could see their profile. So you could see how efficient PHP or other similar programming languages can be when you scale it up on a really large scale like Facebook. But even in a smaller scale like this, if you have a restaurant, website and you have menu items, you could have 10 or 20 or 30 menu items. And instead of having individual pages for every single one of those, you could just have it be dynamic and have one single template or a couple templates for different items. So that's why you would use PHP templates. All right, so why don't we jump into our code editor and get started? The first thing you're gonna want to do is open your a raised up PHP file that you created a little while back. You should have a couple of a raise in there. You're now of men, you and your team members. We're gonna add another array in here, and it's gonna be your menu items. So let's do that. So this will be menu items. Go ahead and create the variable, call it menu items and set up an array perfect. And within our array, we're gonna add multiple other arrays like we did in the previous two arrays. But the difference here is, instead of just writing out a straight up array like so and putting our key value pairs within it, we're actually gonna do something a little different. We're going to give the array itself a custom key name because currently, if you just put array, it's going to have a key. But the key will be a numeric value, so this one would be zero because it's the first item within this array. So instead of having it just be a plane array with a key, um, that with a numeric key, we're actually gonna give it a custom key name, like so. So club dash sandwich equals and there we go. So basically, it's the same thing as if you look up here. We have a key and a value pair separated by the equals and the aero or the greater than symbol down here. It's an array, but it also has a key and what will be of value. So everything in the array is a value. So a race can also have a key accustomed key when it's within their ray here. And that's what we're doing so that we can access this information instead of having to look for it within the array and you'll see why, um, in just a little bit when we start quoting the template. So first stuff we have our club sandwich we're gonna add are key value pairs. We're gonna say title is obviously club sandwich price. We're gonna add a price price Will be, um, an integer So just 11 blurb will be the little text blurb and I have lined up some bacon. Ipsum, it's just bacon ipsum dot com. There we go within her strings. Remember, two separated by a comma and then drink, meaning Ah, a suggested beverage to have with our club sandwich. I'm gonna say club soda seems fitting. All right, Next up, let's add another items. Was gonna copy this whole thing and paste it right after it and just changed the text instead of club sandwich. We're gonna have dill dash salmon and remember here I'm putting a dash in between because we're gonna be using this text this key for the array in our u. R. L. So we need to have have no spaces. And I'd like it to be all lower case with a dash in between. So let's change the rest here. Lemon and percent dill salmon. The costs will be $18. And here I have some more bacon ipsum lined up. There we go you can write your own blurb if you'd like. And obviously, if you're using this for your own website, you're gonna want to have the techs to be something else. But I'm just going to use some bacon. Epsom fancy wine will be the suggested drink beverage with this. All right, Next up, we're going to add another item, and it will be super salad. Super salad will be the name the super salad. And actually, I'm gonna put a ah sub tag. Sup actually means superscript. So the text that will be within the sub tag will actually be small and up a little bit, so you'll see what I mean. So if you have, like, the registered trademark, which we're actually gonna be doing, and percent ridge semi colon, that will give us the registered trademark sign. So it's a small, a little bit of text that's super scripted above the text and you'll see what that looks like. Price. $34. And here I have some veggie epsom lined up because it's a super salad. All right, there we go and are suggested. Beverage A jug. Oh, water. Perfect. Next one. Last but not least, we have our Mexican barba core Very good. The title here will be Mexican barbacoa Fire by cola. The price $23 are expensive. And just to be random, I have some cupcake ipsum lined up boom. Okay. And we're gonna do a beer with a lime suggested beverage. Perfect to save that. And you have your menu items array in order to use this array and make it actually, um, worth our while we need to create a couple different pages. Let's first start by creating our menu dot PHP file. So within your student folder Great. A new file. Call it menu dot PHP. Make sure it's in student. There we go. Open up menu dot PHP within menu dot PHP. It's going to be associated with this knave tab right here. So if I click that I'll go to menu dot PHP. Currently, it is fully empty. Let's change that Start off by adding PHP script at the very top of your template. Let's define a constant and the constant Oh my goodness, There we go is the title, and we're gonna call this page menu and then pipe Franklin's fine dining. So there's our title. Okay, include the header includes Header. That's where the header is located and don't forget to include your footer now if I check this out, make sure I've got everything in there. There we go. There's a basic skeleton that we need to add some content. Let's start off here by adding a div with the i D of menu dash items, but a comment there, so I know where it's ended within our menu items did tag. We're gonna have a Level One header. Our delicious menu paragraph today, but a little bit of text in here Like our team. Our menu is very small us through in an em dash, but dang, does it ever pack a punch aereo creative copyrighting right there. Provided to you by Brad Asi Emphasis Tag. Click Any menu item to learn more about it. All right, there we go. So add that text after that text, we're gonna have a horizontal rule because it's that fancy squiggly graphic that I created and men let's bad an unaltered list. And in here we're going to use our for each loop to access the menu items and put them in an unguarded list. OK, PHP close that over here for each menu items, as this is where we're gonna do something different dish and that is the key. And then the value will be item number. Open the curly brace. Okay, so what are we doing here? Well, let me show you. So here I want to show you at Tuck's Reiter dot com. This guy has a really good explanation of the two ways of iterating through a raise. More specifically, I want to show you the for each loop. So the for each loop there are a couple ways of accomplishing the same thing. So it has two different versions, and the easiest way looks a bit like this. And we've done this before for each array as value and then print the value. We've done that a couple times before, in fact, maybe a handful of times before in the past few lectures, But down here, we are going to be doing something different. So the second way to use for each does allow you to extract keys, and that's what we want to be able to do. We want to be able to extract the key. So when it looks like this for each array as key value print key about whatever you want to put in here. So that's what we're doing here. So we need to be able to extract the key in our for each loop. So here we have for each menu Adams as dish item. So key value. If we go back to our raise PHP file, you can see we did menu items array, and then we have a key and a value pair here. So we want to be able to extract this little tidbit of information and then carry on and also access this invoke because this is going to be important. Let me show you why go back to your menu dot PHP file. So for each menu items as dish item, we're gonna call it dish and item. It could be literally called key and Val, but I wanted to be called dish item perfect in here. I'm gonna add a list item in the list item. I'm gonna have an a tag. Okay. So within our a tag, we are going to add the a treff attribute here, and it's gonna be dished up. PHP. We haven't created additional PHP yet, but we will. And then question Mark, This is where we're gonna be accessing a query string, which I will explain in the next lecture. So just follow along. Right now, Item equals now. This is where we would want to write something like dill dash salmon. But we wanted to be dynamic. We don't wanna have to do something like this. We don't want to do that and change each of these values. And then it's just hard coded. It's not. It's not dynamic, and it's not scalable. So this is what we're going to make dynamic using PHP echo dish, but chemical that simple. So this is going to access the key within the menu items multi dimensional array, so menu items as dish items. So we're grabbing dish, so this will spit out the key within our menu array. So dill salmon, Mexican barbacoa, super salad, so on and so forth. So that's that. And now we want to echo the title. So let's PHP echo item now accessing the item. So this is the value and within their we have key value pairs, so we're gonna access the title key within their There he goes there's a title now within that line, we actually have some super scripted where we have a price in there. But first, we have a super scripted dollar sign very simple and straightforward. And then we're gonna PHP echo the item again. But this time I'm gonna grab the price. Close that PHP tag and then make sure you close this first PHP tag PHP script. You opened it up here, closed up the PHP script and you had an opening curly brace. So that's still left open in our PHP world. We want to close that down here. We did that so that we can put some html within our PHP scripts. That allows you to do that. Save that Now go to your menu dot PHP file Check it out. So we have the text that we added static text. We have our fancy little horizontal rule here. We have our menu items and their links and take note of the the U R L that it is trying to access down in the corner. Here, you could see dished up each be query. String item equals club sandwich deal salmon super salad. Mexican barbacoa. Now that allows us to create a dish stop PHP template and pulling the info that we need. But first I notice one little ah, housekeeping thing. I didn't I don't really like I have the price here included in the link. I don't like how it looks. I don't want to be part of the link, so just move the a tag to the end of the title here. Close it before the sub tag. Save that and you should be good to go. Here we go. So now that isn't a link. It's just the price. All right, so next up, we're gonna have to create our dish dot PHP page. But we're not doing that in this lecture because I want to be too long. So let's do that next lecture. See, there 38. Final: Understanding $_GET: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called understanding Get. And in this lecture, we're going to be briefly covering what get is and how we will be using it to enhance our PHP greatness. So here we go. When the girl the browser requests includes a query string which looks like this, the get collection is created auto magically the string on the left side of an equal sign becomes a variable name. And the thing on the right side of the equal sign becomes that variables value. So, for example, in our previous lecture, we have a link on our menu dot PHP page that navigates to dish Stop PHP Question Mark item equals Mexican dash barbacoa. So the question mark item and then equal sign that is the query string and then Mexican barbacoa is the value of the variable item so that you are l will navigate to dished up PHP , which we haven't created yet and get collection will create a variable called item with the value of Mexican dash barbacoa. We can then use that value to do something specific on our dished up PHP template. It could be a simple as eco Mexican dash barbacoa or something a little bit more useful, like display specific information in an array that has the key of Mexican dash barbacoa. And this is exactly what we'll be doing in our next lecture. So hang on tight, amigo. See there. 39. Final: Menu items: Hey, everybody, welcome back to code dynamic Websites with PHP. This lecture is called coda menu item dynamic template. And in this video, we're going to create a PHP template where we're going to be utilizing the get collection and our query string that we're gonna send to the URL in order to display specific information about a menu item. So, for example, if you clicked on Mexican barbacoa, the menu item template will pull up the Mexican barbacoa info and so on, so forth. So let's jump right in. All right. So firstly, I want to show you what we're going to be building so that you have some idea of what this is gonna look like and how it's gonna work. OK, so here we are on the instructor menu dot PHP page, and if we click on one of these items, let's click on Mexican barbacoa. It opens up a dish dot PHP page, but you can see here we have a query string that says item equals Mexican dash barbacoa and that tells the dish dot PHP template what information to pull out of the array that we created. And so here it displays the Mexican barbacoa information. And so that's what we're going to dio. So let's head back to our code editor and go ahead and create a new file called dish dot PHP. Make sure that is under your student folder, so it's in the right directory and open that up. So first thing you're gonna want to do is add a PHP script of the very Top because we're going to be kind of heavy lifting with some PHP in here. Let's start out by defining a constant, which will be our title. Let's call it Menu Franklin's Fine Dining. Just the generic title up here could even just say menu item. Okay, And now we're gonna need to include our header, as we have done in the past few lectures. Here we go. It's important. Now here is where we ask PHP to check the get collection. So if statement if is set so this means if a variable is set and so we're gonna check the get collection. So if is set, get and then the variable is item that will be passed in the URL. So if the item variable is set and passed through the get collection, then we're gonna create a variable called menu item, and we'll say it is the get item. So this is the variable, and then dish is another variable, not fish dish, and we'll say menu items, menu item and this is what this is. And we just explain this just for a sec. Menu items, if you remember that is in our A raise that PHP file. We have the menu items array and so are checking for the menu Adams array, and we're looking specifically for a an array within this array. So head back to your dish, not PHP template, and we'll look here. So dishes, the variable that were setting and the content of that variable or the value will be the menu items array. And in here, instead of specifically writing a specific array within that array, like Mexican dash barbacoa, it's gonna be dynamic. And so we're gonna be looking for the menu item variable. So whatever the value is, and so the value that that gets passed in this get collection item will be something like Mexican dash barbacoa, which will co respond with the menu items a raise so Mexican barbacoa super salad, dill salmon and club sandwich. You could see how that will end up working out now. So go back to your dish page. And there's something that we're gonna actually do here. Because if I just were to set this variable like so then that leaves us vulnerable to some header injections. Which is, ah, fancy way of saying people trying to hack your code and do something bad, like install malicious code or find information out of your database. So on so forth, you need to be able to clean this out S O that if somebody tries to inject some PHP into your header to find out things that they shouldn't, we need to be able to take that into account. And so we're gonna do is we're gonna create a little function that will strip the bad characters out of what somebody might try and type in the U. R l manually. So we're gonna go up here and just below your include function, we're gonna create a function called function strip underscore bad underscore chars for characters and then in here parameter will be input. Now, this is a little bit of an advanced technique, so I won't go too far into how it all works. But I'll give you the necessary resources to find out a little more. If you're curious, so variable will be output and we're gonna use the built in Petri function. Preg underscore Replace which will check a regular expression to see. Um, if it matches what? What I'm gonna be looking for within my parameter here and then replace the bad characters with, Ah, just an empty string. So essentially what it will do is find the bad characters that we're not gonna allow inside of the URL and strip them out entirely so that it hopefully eliminates any chance of an attack. Okay, so preg replace inside some strings here, we're gonna create a regular expression and regular expressions look scary and are kind of scary and kind of take a little bit of figuring out to do so. Here we go. Ford slash opening square bracket carrot Lower case a dash, Lorik Easy capital A dash capital Z zero, dash nine underscore dash closing square bracket, forward slash. And then that is your regular expression, which basically looks for bad characters. Ah, and we'll strip them out with a second parameter here, which will be an empty string and then another comma. And that will be the input will be checking. So essentially we're gonna be returning output here. So, like I said, this is kind of an advanced PHP move and not really within the scope of this course to explain it fully. But I do encourage you to learn more about preg replace and regular expressions at PHP dot net and search for pregnant place. Feel free to look up regular expressions as well. It's kind of a fun, little advanced technique you could look into, but this is what we're going to be using. This is the advanced built in function that were custom function that we're going to use. And how are we going to use that? Well, down here at menu item, we're gonna wrap the value of this variable in our custom function. Strip bad char's and there does. So now what's gonna happen is if is set to get collection with the variable item store variable in menu item using the get collection, but first stripped the bad characters out of the get collection. If somebody tried ah PHP attack and then stored in here. So we got a good, clean version and then check our array menu items array, store that value in dish. All right, so why don't we just caught a little bit of html down here. Keep it nice and light. Horizontal rule. Let's do a diff give that. Did the i d of dish close it up with a comment? All right, in here, let's do a level one heading and say this is gonna be dynamic PHP echo dish title. Just like we've done in the past. No problem. Then we want to find out the price. So instead of just writing something like static, like $28 gonna use PHP to find out the price of this array. Ah, the specific item in the array. It's a peach be echo dish price. There is our price. But we're going to do a little bit of html around this just to make it look formatted properly. So we're gonna wrap that in a span tag the price PHP script, give it the class of price, and around the dollar sign, put a sub tag for super scripting it. We're gonna make it go a little bit up and look properly for made it formatted. So it's gonna be small dollar sign slightly super scripted beside the dynamic price. Awesome. Alright, paragraph tag. Right after that. A little more PHP greatness Ph b echo dish. And that will be the blurb. Because we have a blurb within our array for each of the items. A break tag going to separate something out here. Paragraph tag. A strong tag within our strong tag. Let's type suggested beverage. We have a suggested beverage in our array, I believe. Actually, I know. And still within that strong tag PHP echo, dish and drink. All right, there is our drink below that we're gonna add another paragraph tag and that we're gonna have an emphasis tag or m tag suggested tip. And we're gonna do another sub tag dollar sign because we're gonna have a dollar sign or some money here. Now, how do we calculate suggested tip? Because that's not actually within our array. So we're gonna do is some more PHP. We're gonna create a custom function to find out what you should tip on the specific item based on the price. So let's do that. Go up here and under your is set. If statement, let's calculate a suggested tip by creating a function call it suggested tip and a couple parameters. Gonna put two parameters, price and tip. Open up those curly races variable called total tip, and that will equal a little bit of math price. Times tip. And then we're going to echo the total tip. But we're gonna take that one step further because this is just gonna It doesn't know that PHP right now doesn't know that this is going to be, um, money. It's not actually a currency, it's just numbers. It's gonna be numbers with decimals, and it does not gonna look like a currency format. Luckily, Ph. B has a built in function called money underscore format wrap that, and we need to tell the the function what money format we're going to use. And that looks a little bit like this. So inside these strings here, percent period to end. Now, if you just look up on PHP dot net the money format, um, function. You'll see all the different types of formats you can use. This is the standard money format, so it would be something like $20.19 or $10.12. It would kind of look like that, you know, 10. Period 12. Something like that. Okay. And so there is our function, and the function won't do anything until we ask it to. So down here, by our sub tag, we're going to say pH b suggested tip, and we have two parameters. So the price we need to start with, which would be dish price, we're gonna send the price of the dish inside of our function. Now, tip will just be 0.20 or whatever suggested tip you wanna put. So this is 20% cause that that PHP script now after this dish tag, horizontal rule and let's put in a h, ref, gonna head back to menu dot PHP. Give it the class of button and previous and let's do and l a quo html entity. Just kind of a left arrow quotation back to menu. Calls up that a tag. Now, don't forget to include your PHP footer. That's very important. Save that now. Check it out. How do we check it out? Go to your menu page and click on any item and check it out. I'm gonna click on club Sandwich, so dish dot PHP item equals club sandwich. What we have here Club sandwich Why don't we go back and try my favorite Mexican barbacoa? There it is. It's got the title. It's got the blurb. It's got the price with superscript dollar sign are bolted suggested beverage and our dynamically generated suggested tip based on our custom PHP function and her sexy little back to menu button with the L A quo. Well, well, that looks good. And hopefully yours looks just as good. If not feel free to go back and hash it out. Hopefully that helped you out and up. Next, we're going to be jumping in to coding a PHP contact form. Alright, see there 40. Final: Contact form: Bouzou. Welcome back to code dynamic websites with PHP. This lecture is called Code a simple contact form. And in this lecture, we're going to be coating a skeleton contact form just with some HTML and some classes and such. We're not going to do any validation yet, but I promise you that we will. But this lecture is just to create the skeleton. So let's jump right in. Okey dokey. So here is the contact form in the instructor folder. So this is what the final outcome will look like. We have a simple contact form that says, Get in touch with us. Your name, your email, your message, a check boxes subscribed to a newsletter and a send message button. We won't be doing any validation or form submission yet. This is just to create the form fields. So let's do this. Open up your code editor, create a new file and you're student folder called contact dot PHP. Again. Make sure it's not outside of your student folder. Keep it inside of the proper directory, open your contact page and start off with your PHP script. And there were going to do the good. Ole defined the title constant that will be Contact us. Franklin's Fine Dining Perfect. We're going to go ahead and include our header that is any includes folder and close that up. And then let's there we go. Don't forget your your quotation marks in your strings. Let's go ahead and add our footer dot PHP earned up yet a PHP because we don't want to forget. That's very important. Okay, so we got that stuff started, uh, figured out. Let's go ahead and add some HTML. So first things first, a div that is gonna have the idea of contact close it up with a comment so that we know there's gonna be a lot of stuff between these tags Gonna have. Ah, horizontal rule Level one header. Get in touch with us. Perfect. Okay, so let's just go ahead and add our form. So we use a form tag. The form has a few attributes that we need to add. That is method, and the value of that attribute will be posts because we're posting the information of this form to the server. Action is where the form will will be posting to. So we're gonna be leaving it empty because it's gonna posted the same page, which is contact up PHP. If we wanted this to submit to a separate page, we would just say Action, contact, success, stop PHP or Success that Peach Peter. Thanks. Not Ph b. So on and so forth, but leaving an empty will submit to the same page. We need an I d. It's gonna be contact dash form. All right. Within these form tags, let's go ahead and add a HTML label tag and an input tag. And the attributes of the input tag will be type text I d will be name and the name will be well name because we're literally gonna use this field. Ah, for your name. So let's go ahead and take that between the label. Say your name. There is an attribute that you need to add to label for accessibility purposes. It's four and then the i d of the input that you want that label to be associated with which is name in this case needs to be the same as the four Attributes. So the reason why I do that is because in the contact page this is the instructor version. If you click on the label. You see how it inserts It focuses the text cursor within that text field that input because some people like clicking in the label. And also it's a bigger target area. So if I can click in the text fields, but I can also click on the label to get me in the text field. Same with the check box. This is a small target area to click, but this is a much larger target area, so its accessibility purposes. And that's how four works with the label associated with the I. D of the input you're using. Go ahead and copy that combination. Paced it out. Change the information. This will be email, your email, the input type. You can put email for that. The idea this and will be email and the name will be email name. The attributes name is what the server will be looking for when you post the forms information. And that's how you access the information from this input. More on that later. Post that one more time here. We're gonna change this from input to text area. Text Area has an opening and closing tag, but also has attributes I d message name will be message. Leave that empty in here. We're gonna change the four to message and this will say, and your message. Okay, let's put another combination here. But first, we're actually going to, uh, switch it around here. So take Thean Foot, cut it out and put it before the label. This type will be a check box. The name will be subscribe, the I d. Sorry, the idea will be subscribed and the name will also be subscribe. Get rid of this one. The value will be subscribed. There's another attribute their for the input for the check box inputs. So you can decide a value of what will be sent to the forms post method. When you submit the form, so the value, if this is checked, will be subscribe. It's the same thing as if I type something in my input. My end me email input. If I typed on my email, the value will be that email. But here we need to determine what the value is. Its checked The label will be afterwards and that will say subscribe to newsletter. And let's change the four attributes to subscribe. This will allow us to check the LaBella's well to check the check box, and we're gonna have one more input and that input type will be a submit button. We're gonna add a few more attributes here. So class button and next already have some pre defined style set up the name of this input will be contact underscore, submit, and the value will be send message. The value is what is displays within the button. So if I didn't put anything, it would just say, Submit, which is the default html text. But we don't want it to say that because that's boring and doesn't convert very well. If people want to click on a form, submit button, so send message should suffice. Okay? And that should be it. Let's check out what you have coded. Here is your contact. A PHP page. It looks like this. And you have your three fields, the your name email on your message and the subscribe to newsletter check box. And you're seven. Send message button. You should be good again. This doesn't do anything if I click it because we don't have any PHP set up, which is what we're gonna do in the upcoming lectures to see there 41. Final: Understanding $_POST: Hey, already welcome back to code dynamic websites with PHP. This lecture is called Understanding Post. And in this video, I'm gonna explain briefly what Post is and how we're gonna be using in our upcoming lecture . All right, so post, much like get is what is called a super global, and they're both used to collect form data in post when a user submits a form by clicking the submit button form data is sent to be processed, whether it's to another PHP page or the current PHP page, and the form data is sent using the post method, and the post collection will then store the information that was sent in that form. So if you have a first name, feel the last name field, an email field and a message field. When you submit that form, the values of those form elements will be sent by the post collection, and then you can use them to send an email, validate your form elements, logging in a user and so on and so forth. So in our example, what we're going to be doing is building a contact form and we're gonna use the post method to submit our form, do some really simple validation and send an email. So that's basically what you need to know about post seeing the next lecture. 42. Final: Form validation: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called Simple form, Validation and Submission. And in this video we're going to take the contact form that we just coded in HTML in our previous lecture. And we're going to add some PHP to do some very simple validation to check to see if people filled out the form fields and, most importantly, submit the form so that you can send an email pretty cool. Let's jump in. All right, so here is the instructor version of the contact page. So this is the final version, and on the front end looks the same. But what matters most is if the's form elements work. If it does some basics validation and if it submits to an email that we specify. So if I just hit, send message and don't fill any of these fields out, I should get a really simple error message notice all fields required. Go back and try again. So that's the same as if I fill out a name and a message, but no email. I'll get the same validation error message, so it's very simple. It's not the most advanced solution but it's something that can get you started. There are plenty of PHP plug ins that you can use that do a much better job. And you can also double up and use, um, JavaScript or J query plug ins that will you can use on top of your PHP so you can make it ultra secure. But in this tutorial, we're just gonna do very simple bare bones validation method. So let's jump into our code editor, make sure you have the contact a PHP file open within your student folder. First thing I'm gonna do is just pace a really big comment here in the PHP script just so you can see what we're gonna be using here. I'll explain in a moment. So in the form in contact a PHP. So the form that you just built in the last lecture the name text field has the name attributes of name. If the user submits the form, the post name variable will be automatically created. Remember our last lecture? We briefly learned about the post collection and that post name variable will contain the text that they typed into the name field. The post email variable will contain whatever they typed in the email field. So is a brief little overview of the PHP that will be using in this follow the script that we're about to build. We're using Preg Match, which performs a regular expression match. You can learn more about it Here. You can always open this up in the instructor folder looking the contact. A PHP page, a reference. All these is set determines if variable is set and not know, meaning empty or nothing is in it. Post is an associative array of variables passed to the current script by of the http post method that we just learned about the post collection. Their last lecture trim strips, white space or other characters from the beginning and end of a string. So if you typed in a text field, for example, on your wrote space like you hit the space bar wrote your name So space Brad and then space . The trim function will strip this white spaces from the beginning and the end, so you have a clean input exit, outputs a message and terminates the current script. Di is the equivalent to exit just looks more intense. Word wrap wraps a string to a given number of characters. So, for example, in your message field, if you write 140 characters, you can wrap the the text to have a maximum line with our character with of a certain amount of character. So if you said word wrap 50 then that that 140 character message will have multiple lines of 50 character lines. So whatever that works out to male sends mail. All right, so let's move down here to your contact div, and we're going to start out, and we're gonna going to get her hands really dirty. So hang on tight. Alright, Right under your level one heading. Let's do some stuff. Open up a PHP script and first thing we're gonna do is check to see if the contact submit button was pressed. Do that by using if is set. And then we're gonna check the post collection to see if contact under court underscores submit was pressed opening, opening and closing curly braces. So contact submit. Is this right here? Our input button the name of contact. Submit this checks to see if the post collection sent us a variable checks to see if the context amid button was pressed more or less. All right, so if that is the case, then we can start grabbing the information from our form. So what we're going to do is create some variables. Let's say name and name. Well, equal post and then name. Because that is a name attribute of the text field name where you write your name right here. Copy that. Paste it below. Change some stuff around email, and we're gonna check the post collection for email and store that variable from the post collection in a cleaner looking variable. We're doing this just so that it can look a little cleaner. We can just leave this as is, and utilize them a little further down in her script. But this just makes it a little bit easier to read. Less typing, too. All right. And last one here will say message or MSG for message. Post message. Okay, so I can leave this as is. But as I mentioned before, we're gonna be using the trim function, and I want to use the trim function just to clean our name and email variables up a little bit. So we just wrap the trim function around each of these. There we go. So trim around name and email. We don't need to trim message because, well, it's not as strict as your name or your email. Specifically email where it needs to match an exact email on the message. They could essentially type whatever they want. And that's not necessarily true, because they could try and use the message field as a way to attack your website. And in some malicious code. Some people are very good, but this doesn't really cover the scope of how to deal with that. It's a very easy Google search, so turn up the name and email. So now what we have to do is some very simple what we need to check to see if people are trying to hack our contact form by using what's called a header injection. So what is a header injection? Well, it's very similar to a email injection that an attacker will use to send out spam from your mail server using your contact form so they will hack the name and email fields or whatever feels like an access, specifically name, email or even the subject fields to inject PHP code and change who the email will be going to. So instead of just the one person you've written and your PHP script, they will try and change that to a whole bunch of people that they probably found their emails on the Internet using email farming or they just have a list of their own. And then they spam all of those people with whatever it is that they spammy those people with could be products services. Could be pornography could be a bunch of crap, and it will look like it's coming from you and you don't want that. So we're gonna do a really simple, um, preventative measure for email header injections and you can Google how to go even more in depth. That course doesn't really cover a really in depth solution, but we're gonna give you a very simple one, So follow along. So let's check for header injections. Okay? Function. We're gonna create a function call. It has header injection and variable passing here, and we'll to say string and then we're gonna return preg match. So performs a regular expression match searches and replaces, and we're gonna use a regular expression ford slash opening square bracket. Backslash are backslash and closing square bracket for it slash And then after your string there, a comma and then the very well that you passed and here is an argument. Okay, so then what we can do is below our if statement sorry within our if statement after the variables, check to see if name or email have header injections. So we just do that by going. If House header injection and the string will be replaced, the argument will be name or house header injection, email. If that is the case, then kill the script or die. So if true, kill the script. There we go. So this is some very basic, um, very basic function that will just see if somebody is trying to perform a header injection with your name or email field. Save that Now, let's, um, do some basic validation. Very, very simple. Very simple. If statement and this is all we have to do so after the header injection, if statement, let's add another if statement this if statement will check to see if the name email and message variables are empty. Very simple. If not name, which means if name is false or if it's empty. So if nobody posts anything in the name field and this will in fact be true if not name or if not email, or if not, message, we're going to say all of them are required by doing this. So if not name or if not email or if not, message meaning. If any of these are empty, then this if statement will be true. And if that is the case, then echo some html here will say well before heading and will give it the class of error. Noticed. I use double quotations in here and therefore I used single quotations on the outside Oh, fields required. And then we're gonna add and a tag. Okay, the H ref will be contact up PHP. The class will be button and block, and the text will be. Go back and try again. Then we're going to exit that script. All right, I'm gonna call this part one of this lecture because we solve quite a bit left to do. And I don't want the lecture to get too long in one Go. So we'll see you in the next lecture where we will continue from this exact spot. See, there 43. Final: Form validation, part II: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called Simple Form Validation and Submission Part two. Let's jump right in. Okay, the next thing that we want to do is set up and build our email message. So essentially, what we did here is we performed all the very basic, um, actions will need to do when checking a PHP form. So we checked to see there is a header injection killed the script. If there was if not, then we continue on down. We have to check to see if our contact submit form context, mate Button was pressed. And then there we start some variables that the header injection test check to see if the fields were empty. If we're all good, then we're gonna keep going down this script. So what we need to do is construct this email message, Add the recipient email to variable. So who is going to receive the message from this form? Let's call this variable, too. Let's use your own email here. I'm just going to say you're at gmail dot com. You could put your actual email so you could test this a little later create a subject, so that will be subject. Variable will call it. And we're going to construct a little message in here Name because we know the name. Variable sent you a message via your contact form. That would be the subject. Next up, we will construct the actual message. And this is where we're going to create a message. Variable, most say equals name. So this is what's gonna show up in the actual body of the message name. And they were going to say the name variable. And in an email, we need to break this onto a new line. And we can't post html in here in your email message in a simple contact form. So we need to do a line break and to put do a line break in email, you just go back. Slash are backslash, and that is a line break down here. We're gonna do the message variable again, but we're gonna can captain e a value to that and will say email email. Backslash are back slash in message variable can captain eight. Another value onto the message. Variable message. So the message itself we're gonna break a line here. Backslash are back slash and and then the message variable or the message variable. So the reason why did this is because I want the message. Ah, heading. I guess you could call it on a different line than the message itself. Because the the message in the text area will probably be multiple lines. And I wanted to look clean. Okay, so we've constructed the message, created the subject out of the recipient email. Now, let's check to see if he subscribed. Check box was checked. So if the's subscribe check box was checked So that's like this If if statement is set, check the post collection for the subscribe value here. So the name subscribe from that check box that will be sent along in the post collection it checks to see if it was actually checked. Okay. And post subscribe is equal to subscribe. Now, what does this mean? Wasn't this good enough? Post subscribe. If that was set technically, yes, but we're wanting to do here is double check. So if post subscribe, it was sent along in the post collection and the value of it is equal to subscribe. Then let's carry on ad a new line to the message. Variable message, Captain. A new value. Let's do a couple line breaks. Backslash are back slash and backslash are back slash in please. Now you don't need to put a space here. You get us. Read it right afterwards. Ad the email variable to the mailing list. Line break access are back slash in perfect. Okay, outside of your if statement since we've checked to see the check box was checked. Let's make the message very well. Look a little bit more tidy. So message equals. This is where we use the word wrap function word wrap. So we need to pass it a variable string and remember numeric value of how wide you want. How many characters you want each line to have 72 is that I'm going to say There we go. So this will take the message. Wrap the long string of text that will likely be typed into it and wrap the message to 72 lines per line or sorry, 72 characters per line. Okay, now we need to set the male headers, and male headers are required when you send an email because it lets the email client like Gmail or Hotmail Apple Mail. So on so forth, the mind version content tight, Who it's from and if it's a priority, things like that. So let's set the mail headers into a variable So a headers variable. Let's start off with the mime dash version 1.0, and break the line back Such are back slash in so that my inversion is 1.0, headers. What's can cat NATO value on there? Content type? This is just plain text. So text slash plane and the char set equals I s 0-88 five, nine Dash one, Break the line. You're probably wondering, how do you know all this off by heart? Well, I don't. I did it once by following an instructor who taught me how to do this back a few years back and did some tutorials. And I just kept it in my default kind of template. Contact, form, script. And I just copy and paste it every time. You don't need to memorize this. You can look it up to see the different things you can send through mail headers. Very easy to find tutorials online, but this is kind of basic way of doing it. Don't worry if you can't remember it, because I certainly do not. Okay. Next line. Headers. Cat Need another value in that variable from Who is the message from? Put us the Colon and in a Space. And then we're going to Cannes. Katyn. Eight. A value here, actually, why don't we just do it in here from name and then email? And let's break that on to a new line. I think this should be good. So this is the proper syntax of how an email is sent, who it's from. So the names, the person's name like Brad and their email like your at gmail dot com it's That should be good. Okay, another headers, Caffeinated value, X dash Priority one and then break the line. Now I believe one means high priority where zero means no priority. I'm pretty sure that's the case. This just does its best to make sure that the email is sent to your inbox and not flagged as spam. However, if somebody is sending you spam, if you have a smart inbox, then it will likely filter it Anyway. So another one of these we're going to say X dash M s male dash priority. And instead of one, it will be hi and then to line breaks are and so these air just to set the priority of the the male type priority or not again, You don't have to memorize these. Just keep it in a script copy and paste it for later use. Now we get to do something cool. Send the email. We did all that work to just type this male. Put some arguments in here have some parameters to subject message headers That is the syntax of the male function. So you send the mail first argument is too. Then subject, then message. Then the headers saved that. Now we're not quite done. I'm going to remove this last curly brace from our PHP if statement way up here, if is set post contact submits because we don't want it to end there. We need to have some html show up after the email was sent. So before you forget, put a PHP else statement and then remove the last closing curly brace. Close that PHP script because we're going to basically in between the first Petri script and the else statement here. We're gonna check to see if the post context, um, it was clicked. Do all this sort of stuff and then show some html and then else we're gonna show the contact form. So here, we need to show success Message after email has sent. Okay. Level five heading. Thanks for contacting Franklin's paragraph tag. Please allow 24 hours for a response and then one more paragraph tag with an a tag in there , we'll go to slash final class, but in and block that will be a tag and will say l a quo for the H male entity. It's like a left error arrow go to page that will send them to the home page of the click that button link. Okay, so then we have to make sure to close this else statement after our form. Very simple. Ph B boom. Done. And let's just toss and h r. And here just for fun. Okay, so let me just show you really quick. Make sure you got everything. PHP script has a whole bunch of stuff in here. Checks her head allergic injections, submits the form, checks the variables, sends the email when you're done sending the email shows success message on the page else if the contact submit button was not pressed, that means nobody filled the foreman yet. So just show the form and then close your PHP script right here with the closing curly brace of your if else statement very big and juicy. But now we should have a working form. It is worth noting if you're using a local host like a local server on your computer, the email might not send, which means you need to have an actual web server. So if you have a website or a domain than upload the site there and then try the contact form there, but we're actually gonna try it here on local host. Sometimes it works for me. Okay, here we are on the student contact form. I've changed the email My the email variable the who It goes to to my actual email, not just your at email dot com to see if it actually works. So first hit, send Machin message without anything to see if you get the validation perfect. All fields required go back. So that should work. Go ahead and fill out the form subscribe to newsletter Send message. Let's see what happens. Thanks for contacting Franklin's. Please allow 24 hours for response to go back to home page. Now I'm gonna check my email, see if I've got the email. Here it is. Brad sent you a message by your contact form. Click on it. Here we go your at gmail dot com. That's actually a fictional email, but the person would hopefully put their actual email in there to me. So name Brad. Email your gmail dot com message. Hello, Testing this old form. Please add your at email dot com to the mailing list. So there's the basic email message from your contact form. Hopefully, you got that working. If not, go through the lecture again and do your best. Try your darndest to get it working, and that basically wraps up the majority of our tutorials and our course. But we have a little bit left, so hang in there and I'll see in the next lecture 44. Final: Upload your website live: Hey, everybody, welcome back to code dynamic websites with PHP. This lecture is called Uploading our website live on the Web. And in this video I'm gonna briefly show you how you can purchase some hosting and then upload your website whether it's this site right here that you just coated, or a different website that you might want to coat afterwards with skills you've learned live on the web so that you could view it on your own domain name. Let's do this. All right. So the first thing you're gonna want to do is set up some hosting for your website. If you don't have any already. My first recommendation is to go to Brad hacia see a slash resources that is my blog's resources section. I listed a bunch of useful resources, tools, applications and websites to help make your life a little bit easier. They've certainly helped me out and it's good to know that all these links, for the most part, are my affiliate links and I will earn a small commission should you decide to make a purchase. The best part is that it is at absolutely no cost to you. Think of it as like a free tip for helping you out. I provide you with a link to a resource. I help you out. You give me a free tip. No cost to you. It's pretty cool if you don't want to use these links. Totally fine. So the 1st 1 of my lucky seven I like to call is just host. It is my preferred host. I used for all my websites and courses and everything like that. You can click on that, or you can go to brad. HAC dot c a slash PHP host. That'll take you to just host from here. All you really need to do is just hit, get started, fill out the information, purchase a hosting package and then you'll be sent an email with all of your log in information for your control panel and for your FTP protocol that stands for file transfer protocol. I have a course and a few free tutorial videos out how to to set up hosting really quickly . One of them is on YouTube, and it is called how to start a block in 10 minutes with just host, and I'll provide a link to that also, I have a free course called the Web, hosting one A one on you to me and YouTube. So check those out if you want to know a little bit more about hosting once you're up and running. If you're using CODA, what's really great is that it has a built in FTP. You can also download and purchase different file transfer protocol applications, but my favorite by far is Koda. I've already set up on my Web server. Brad has C dot c a. Fuller called code PHP, and all I need to do is drag the contents of my final website into the code PHP directory. Wait a few seconds for the upload. It's a very small website. It shouldn't take very long and then navigate to Brad Husi, not see a slash course slash code PHP, and that should pull up. The site here does. I can go through, check out all this stuff. Everything should work, and then there's a contact form. Perfect. So that's it. That's really how you upload your website by a FTP file transfer protocol. And it's good to note that when you buy a hosting package, you need to make sure that it supports PHP. There are a few hosts that don't but just host and other hosts of a similar value and quality do support PHP. So it's good to know that if you want to build a WordPress site or a PHP site, things like that. It's good to know if they can support PHP, and the host that I recommended most certainly does. So hopefully this lecture was helpful to you and I will see you in the next lecture where we wrap everything up, see there. 45. Wrapping up!: Hey, already welcome back to code dynamic websites with PHP. This lecture is called wrap up and where to go from here? My friends, this is the end of the course. Thank you so much for taking the course. I encourage you to put what you've learned in this course into practice immediately start taking your static websites and convert them into dynamic websites. I'm sure there's a bunch of ideas running through your head after taking this course hand code every day. Master what you know and challenge yourself. You'll get super good that way. And if you found value in this course, please leave a rating and a review if you're on you to me or share it with your friends, your family, your colleagues. If you know somebody who wants to learn how to code or wants to get better at PHP, send them this course. If you want to learn more about HTML and CSS that check out my course, build a website from scratch with HTML and CSS. You can use the coupon code dynamic PHP to get 50% off. If you want to stay in the loop with me and about my new courses and updates, then subscribe to my Blawg at Brad Husted. Out see a slash subscribe Follow me on Twitter at Brad Husi and I'm also on Facebook at facebook dot com slash brad Husi Feel free to check out my resources page at Brad House Did not see a slash resources. Lots of cool stuff there that can help you out. And if you haven't already, check out my other courses at u to me dot com slash u slash brad Husi. I really appreciate you taking the time and following along with this course in the best cheers and happy coating. 46. Please leave a review: Hey, already welcome back to code dynamic websites with PHP. And before we move on, I have a quick favor to ask you. I've dedicated thousands of hours to creating great content for my students. And the reason I can reach so many people at this point is because of people like you. This course alone has taken me months to create, and I'm not asking you to pay anything for it. All I ask of you is one little thing. If you're checking out my course from YouTube, I would love if you could share this course with your friends, family and work colleagues. And if you're checking this course so from you to me, I would especially appreciate if you could give me a quick rating and review using the star rating and the review box. You can leave me an honest review and you can always change it later. Should you have a different opinion? By the end of the course, you're awesome. Scene the next video