If else embedding inside html
There are a few different ways you can embed PHP code inside HTML. Here are two options:
- You can use PHP tags to enclose your PHP code, like this:
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<?php
if (condition) {
// PHP code to be executed
} else {
// PHP code to be executed
}
?>
</body>
</html>
Watch a video course
Learn object oriented PHP
- You can also use short PHP tags, which are slightly shorter versions of the PHP tags shown above. Here's an example:
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<?
if (condition) {
// PHP code to be executed
} else {
// PHP code to be executed
}
?>
</body>
</html>
Both of these options allow you to embed PHP code inside your HTML document. The choice of which one to use is largely a matter of personal preference.