Blogger Information
Blog 17
fans 0
comment 0
visits 11540
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
创建一个页面,并用php自定义变量——2月20号
iL的博客
Original
825 people have browsed it

实例

<?php
/**
 * Created by PhpStorm.
 * User: 92975
 * Date: 2019/2/20
 * Time: 21:00
 */

//案例1:使用heredoc语法添加大段代码,并用变量替代其中的一些数据
//自定义变量
$title='我是自定义变量';
$tableTitle='同学信息统计表';
$name=['张三','李四','小明','小红'];

//使用heredoc语法输出html代码与php代码的混编
echo
<<<"ONE"
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <title>$title</title>
     <!--样式-->
  <style>

      /*定义表格大小与表头颜色*/
      table{
          width: 500px;
          height:200px;
      }

      /*表单居中*/
      table{
          margin: 15px auto;
          text-align: center;}
      p{
          text-align: center;}

      /*添加边框*/
      table,th,td{
          border:1px solid #000;
          border-collapse: collapse;}

      /*调整标题的样式*/
      caption{
          font-size: 1.5rem;
          margin-bottom: 30px;}

      /*调整表头样式*/
      thead tr{
          background: red;
      }
  </style>
 </head>
 <body>
 <!--表单1-->
   <table class="chat1">
     <!--<caption>同学信息统计表</caption>-->
     <caption>$tableTitle</caption>
       <thead>
        <tr>
           <th>姓名</th>
           <th>年龄</th>
           <th>身高</th>
           <th>体重</th>
           <th>爱好</th>
        </tr>
       </thead>
       <tbody>
        <tr>
           <td>$name[0]</td>
           <td>19</td>
           <td>180cm</td>
           <td>70kg</td>
           <td>电脑游戏</td>
        </tr>
        <tr>
           <td>$name[1]</td>
           <td>18</td>
           <td>188cm</td>
           <td>80kg</td>
           <td>手机游戏</td>
        </tr>
        <tr>
           <td>$name[2]</td>
           <td>20</td>
           <td>178cm</td>
           <td>60kg</td>
           <td>旅游</td>
        </tr>
        <tr>
           <td>$name[3]</td>
           <td>17</td>
           <td>158cm</td>
           <td>40kg</td>
           <td>看书</td>
        </tr>
       </tbody>
   </table>
 <p>统计人数:4人</p>
 </body>
</html>
ONE;

echo '<hr>';

?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

 

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post