What is the difference between PHP and HTML?
Here you go, practical demo time:
If you’ve got a webpage you want to display a message on: ‘Hi There!’, here’s how you would do it in HTML:
<h1>Hi There!</h1>
And in PHP:
echo ‘<h1>Hi There!</h1>’;
Your HTML file will be named with the extension ‘.html’, whilst your PHP file will have the extension .php.
HTML can run from your desktop too. If you’ve got a file index.html sitting on your desktop, you can just double click on it and it’ll open up and render the text on your browser. PHP, on the other hand, requires a Web Server to run on.
So, PHP’s main job is to process some data and render it in a language the browser understands (which is HTML).
Here’s how a typical webpage load works:
- User enters URL eg: http://somewebsitethatdoesntexis...
- The browser sends the request to the server where the url is pointed to.
- The server reads the request, understands that it has to render a certain file, lets say, index.php
- The server then executes the code in index.php, and generates some HTML.
- This HTML is sent back to the browser, which then renders it.
Hope thats clear! Reach out if you need further help!