In this course, you'll explore the basic structure of a web application, and how a web browser interacts with a web server. You'll be introduced to the request/response cycle, including GET/POST/Redirect. You'll also gain an introductory understanding of Hypertext Markup Language (HTML), as well as the basic syntax and data structures of the PHP language, variables, logic, iteration, arrays, error handling, and superglobal variables, among other elements. An introduction to Cascading Style Sheets (CSS) will allow you to style markup for webpages. Lastly, you'll gain the skills and knowledge to install and use an integrated PHP/MySQL environment like XAMPP or MAMP.

Taught By

Charles Russell Severance

Professor

Transcript

So on we go about the PHP language. Like I said, it comes from the C language. You see curly braces. We're also going to learn JavaScript and that has curly braces. No significant whitespace. Again, that's all from C. There's some things where PHP is inspired by Perl. Dollar signs for variables, which is one of the things that people find annoying about it. And associative arrays, which people love. And the idea is is that PHP is a language. Although you can use it for things other than HTML, it really is intended to be an HTML templating language. And it really exists to serve web applications. And that's one of the reasons that I really like it. One of the things about PHP is it's a productivity tool. It's not a tool that's really designed as a teacher. So if you take a Python class, Python blows up all the time. PHP doesn't blow up. It figures if you typed it, you probably meant for it to happen. So PHP is trying as hard as it can to just interpret what you're saying and just do what you want. And the idea is you're supposed to be able to write code fast, you know what you want to do, sometimes errors are silent. So you're supposed to be a responsible programmer. And so you may find this responsibility on your part as like, oh wow, why don't you stop me from making mistakes? But that's not necessarily the philosophy of PHP. So as I said, PHP is like an extension of HTML. So we create files that end in .php. And in that they start the first line is html. And so this is just html. And at some point you switch into php with this special kind of tag. And it turns out there are a couple of things. This <? is something that was built into HTML for various programming languages, kind of like escape to the server side. So the browser is interpreting this, and then the server's running this code as it's producing the response cycle, request response cycle. And so you switch, and now you're in the PHP language. This code emits output. The output to this code, like an echo statement, which is a print statement, that actually becomes part of the page. And then it runs code. We're going to answer 6 times 7. You'll notice semicolons to end statements. Another echo statement. Some more output. Some more output. So what happens is what the browser sees is not this code at all, but instead the output that's produced by that code. And now the ?> than finishes that. And now we're back into HTML. And so if we run this we're going to see this HTML, the results of this PHP execution, not the code itself, and then that that HTML. And so that's what it looks like, okay? And so here it is. The answer's 42. We can't really tell the difference between just looking at the HTML. This came from the static HTML part, this came from, the paragraph tag came from the template. And all this text came from this code running. And then another paragraph came from that. So you switch back and forth. And just because I showed only one, you can have a long file, you can switch in and out of HTML and PHP as much as you like. Sometimes we'll switch in and out of HTML and PHP in a single line. We'll just kind of like right here, in between Dr. Chuck, we will do less than question mark PHP. Some stuff. Question mark less than. And we can do it right in the middle of a line, it doesn't have to be a whole block of text. It can be right in the middle of the line. And then the output of this is stuck into the HTML right at that point. Just for completeness, PHP is really designed as a web language, and that's why I like it. But I've also seen people who only know PHP and have done things that are command line with PHP. You can open files. You can read them. PHP is good at parsing strings. But, I would say that Python is probably a better use of command line if you're going to write command line application. I saw somebody over their shoulder, I'm like really, you know that? So, I didn't realize it, but you can. But I don't recommend it. So up next, we're going to talk about the basic syntax of PHP.

Explore our Catalog

Join for free and get personalized recommendations, updates and offers.

Coursera provides universal access to the world’s best education, partnering with top universities and organizations to offer courses online.