![]() ![]() php file, and that the way to make the examples come to life and “do something” is to access that file in your web browser. And again, a main thing to understand is that you’d be seeing these examples inside a. php file into HTML markup in your browser-then you understand the fundamentals of PHP’s echo. If you’ve understood the code and screenshots above-and how that code makes it from a. When we tell PHP to echo those things, they both get printed straight onto the (web)page as pure HTML, and the result is two words of italicized text. Your browser doesn’t deal with tag to surround them and make them italic. With this new mixture of HTML and PHP, the markup that’s outputted to the page is going to change significantly:ĭo you see what happened there? The PHP that we echoed got “consumed” to generate pure, clean HTML. Now for the good part: let’s put actual PHP into example.php, to show you what PHP’s echo can do: However, if we do want to write PHP at any point, we will have to be working in a. This is because PHP outputs HTML anyway: all we’re doing is skipping the step of writing PHP in the first place. php files to be just pure HTML, with no actual PHP in them. That teaches us something important: it’s fine for. Now, what would happen if we were to change our example.html file to be named example.php, while keeping its contents the same? The answer is simple: other than a URL change, nothing would happen. And what do we mean by “the page”? We mean the webpage: the screenful of words and other things that your browser shows you when you visit this URL. So our outputted markup is not just words: it’s also HTML tags like and that structure and change what appears on the page. Let’s use Google Chrome’s “Inspect Element” tool to see that markup itself: In this dead-simple example, what is the “outputted HTML” we’re talking about? It’s not only the phrase “Hi, I’m pure HTML.” itself, but it’s more than that: It’s all the HTML markup that the web server sends to your browser for your browser to be able to generate the page we’re looking at. If we then upload example.html to the web server that the domain points to, we can do something cool: we can open our web browser, visit /example.html, and see the text “Hi, I’m pure HTML.” in a nice big header on an otherwise blank page. Now, let’s pretend that we wrote the code above into a text editor (such as Notepad), and saved the whole thing as a file, let’s say example.html. ![]() We’ll start this demo with a code example that is pure HTML, no PHP at all. Now: Here’s a detailed, sequential demo that explains both what it actually means to say that “PHP outputs HTML,” and to say that “ echo is how PHP outputs HTML.” Code Demo: How PHP Uses echo to Output HTML ![]() Please give both those links a skim if you find yourself wanting more context for the rest of this section. And it’s especially helpful to know the difference between “server-side” and “client-side,” to the point where the phrase “PHP is a server-side programming language” has meaning. In other words, a beginner tutorial should not just say “great, now we print the result to the page with PHP”: it should explain what that actually means.įor that conversation, it’s helpful to know the basics of the software environment ( most commonly LAMP) that PHP runs in. I find that PHP tutorials often overlook explaining, step-by-step, how PHP changes its broader software environment. PHP Outputs HTML, and echo is How It Does So ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |