This is a very easy thing for an experienced PHP web developer. But this is a problem for newbies who are just starting to get involved in the PHP programming language. So here is how to embed PHP code in regular HTML code.
Embed PHP code in regular HTML
Create a hello script named:
<html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html>
In the HTML code above, print Hello in the PHP code. Writing PHP code in HTML requires the use of <?php ?> tags. Integrating PHP and HTML is a very simple thing.
We can also write more complex PHP code in HTML, requiring the use of <?php tag and end with ?> tag.
More advanced code examples:
<html> <head>PHP HTML Integration</head> <body> <ul> <?php for($i=1;$i<=5;$i++){ ?> <li>Item No <?php echo $i; ?></li> <?php } ?> </ul> </body> </html>
Output result:
Item No 1 Item No 2 Item No 3 Item No 4 Item No 5
The above is the entire content of this article, I hope you like it.