How To Use PHP In HTML

The Confused Creative
2 min readApr 13, 2021

--

In this article I’ll show you how to use PHP in your Html page as a complete beginner.

PHP is an Html embedded server-side scripting language, the code is interpreted and run on the server side. Much of its syntax is borrowed from C, Java, perl script languages. PHP is designed to interact with HTML, the PHP scripts can be included in an HTML page without a problem, although it can be very tricky for beginners.

A PHP script starts with “<?php” and ends with “?>”. In PHP, keywords ( if, else, while, echo, print, etc.), classes, functions, and user-defined functions are not case-sensitive, but the variables are ($color and $Color would give different outputs).

Different ways to embed the PHP into your Html page

PHP start tag “<?php” and the PHP end tag “?>”

  • This is the recommended usage of PHP in Html page. Know that, the PHP code goes into the body of the Html as seen below.
  • The embed PHP code is the standard one, this PHP code has been embedded in a script tag.
  • PHP comes with a variation which you could make use of if you want to shorten your code. This is the short_tag option, it shortens <?php to <?. Note that, if you want to build a website compatible with as many platforms as possible, you shouldn’t rely on short_tags.
  • You can also link a .php extension in the html page the way you link an external style sheet for css instead of styling in the html page.
  • It is also very possible to change the file extension from “index.html” to “index.php” .

These are the simple ways any beginner can use PHP in an Html page.

--

--

The Confused Creative
The Confused Creative

Written by The Confused Creative

Multifaceted Creative. MERN stack Developer. Certified PT

No responses yet