How to embed PHP code in HTML
It is very easy for an experienced PHP Web developer. But this is a problem for beginners who are new to the PHP programming language. So here we will introduce how to embed PHP code in regular HTML code.
Embed PHP code in regular HTML
Create a hello script named hello. php:
?
1 2 3 4 5 6 7 8 |
<Html> <Head> <Title> PHP Test </title> </Head> <Body> <? Php echo '<p> Hello World </p>';?> </Body> </Html> |
In the preceding HTML code, print Hello in the PHP code. You need to use tags to compile PHP code in HTML. Integrating PHP and HTML is very simple.
You can also compile more complex PHP code in HTML, and you need to use tags.
More advanced code example:
?
1 2 3 4 5 6 |
<Html> <Head> php html Integration <Body> <Ul> <? Php for ($ I = 1; $ I <= 5; $ I ++) {?> <Li> Item No <? Php echo $ I;?> </Li> <? Php }?> </Ul> </Body> </Html> |
Output result:
?
1 2 3 4 5 |
Item No 1 Item No 2 Item No 3 Item No 4 Item No 5 |
The above is all the content of this article. I hope you will like it.