t195.php

<?php
//case 10 网页布局
//定义常量,防止直接访问引入页面
define('WEBTEST','test1');
?>
<html>
<head>
    <meta charset="UTF-8">
    <title>网页布局</title>
    //样式表
    <style type="text/css" rel="stylesheet">
        .title
        {
            width: 98%;
            height: 100px;
            background-color: #cccccc;
            margin: 3px auto;
            text-align: center;
        }
        .content
        {
            width: 60%;
            height: 600px;
            float: left;
        }

        .content .lst
        {
            width: 90%;
            height: 580px;
            margin: 0 auto;
        }

        .content .lst .pic
        {
            float: left;
            width: 320px;
            height: 160px;
            background-color: #CCCCCC;
            margin: 5px;
            padding: 5px;
        }

        .content .lst .pic img
        {
            width: 300px;
            height: 150px;
            padding: 5px;
        }

        .side
        {
            width: 38%;
            height: 600px;
            float: right;
        }

        .side ul
        {
            list-style: none;
        }

        .side ul li
        {
            text-indent: 20px;
        }

        .side p
        {
            margin: 0;
            padding: 5px;
            font-size: 20px;
            color: #7f7f7f;
        }
        .footer
        {
            width: 98%;
            height: 100px;
            background-color: #cccccc;
            margin: 3px auto;
            text-align: center;
            clear: both;
        }
    </style>
</head>
<body>
    <div class="title">header</div>
    <div class="content"><?php include ('./t196.php');?></div>
    <div class="side"><?php include ('./t197.php');?></div>
    <div class="footer">footer</div>
</body>
</html>

t196.php

<?php
//访问限制
if(!defined('WEBTEST'))
{
    exit('No access!');
}
//图片列表
$books = array('cat.jpg','cat.jpg','cat.jpg','cat.jpg','cat.jpg','cat.jpg');
?>

<div class="lst">
    //:,endforeach是php 7 新语法
    <?php foreach ($books as $book):?>
    <div class="pic">
        <img src="./img/<?php echo $book;?>">
    </div>
    <?php endforeach;?>
    <div style="clear:both"></div>
</div>

t197.php

<?php
//访问限制
if(!defined('WEBTEST'))
{
    exit('No access!');
}

?>

<h2>PHP培训班开训信息</h2>
<ul>
    <?php
    //数组列表
    $arr = array(
        array('PHP基础班','西安--第01期','兰州--第02期','白银--第03期'),
        array('PHP中级班','成都--第11期','重庆--第12期','宁波--第13期'),
        array('PHP高级班','杭州--第31期','上海--第32期','郑州--第33期')
    );
    //数组首个元素放入p标签,其他放入无序列表
    foreach ($arr as $values)
    {
        foreach($values as $k=>$v):
            echo $k > 0 ? "<li>{$v}</li>":"<p>{$v}</p>";
        endforeach;
    }
    ?>
</ul>

 

更多推荐

php教程--案例10(网页布局)