Codementor Events

What is the difference between PHP and HTML?

Published May 16, 2018Last updated Nov 12, 2018

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:

  1. User enters URL eg: http://somewebsitethatdoesntexis...
  2. The browser sends the request to the server where the url is pointed to.
  3. The server reads the request, understands that it has to render a certain file, lets say, index.php
  4. The server then executes the code in index.php, and generates some HTML.
  5. This HTML is sent back to the browser, which then renders it.

Hope thats clear! Reach out if you need further help!

Discover and read more posts from Rashmi Bachani
get started
post commentsBe the first to share your opinion
Show more replies