How to embed HTML code in PHP

1.Output HTML code with echo

<? php
$int=rand(0,1);
if($int==1){
Echo "< p > the random number obtained is 1 < / P >";
}else{
Echo "< p > the random number obtained is not 1 < / P >";
}
?>

2.Embedding PHP in HTML code

In this way, you can add Code.

<! DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<title>Hello World</title>
</head>
<body>
<? php
Echo "Hello world! This is the text";
?>
</body>
</html>

3.Use (< < <) markers

This is the first time I saw it in the template code of PHP168

<?php
      print <<<EOT
      <div class="slidecont">{$label[deepblue_mainslide]}</div>
     <div class="newcontainter">
          <div class="head">{$label[deepblue_mainh1]}</div>
          <div class="cont" id="Tab1">{$label[deepblue_maint1]}</div>
          <div class="cont" id="Tab2">{$label[deepblue_maint2]}</div>
      </div>
      <a href="$rs[url]" title="$rs[descrip]" target="_blank">$rs[name]</a>
 EOT; 
 ?>

4.Directly reference HTML files into PHP

An HTML file (test. HTML), the main code is:

<body>
<p>I'm an HTML code</p>
</body>

Use PHP’s include () function to connect the external HTML file to the PHP file

<? php
include ("test.html");
?>

Output:

Leave a Comment