dounue1965 2015-12-28 08:36
浏览 38
已采纳

PHP - 从另一个文件加载标头

I've run into problem whereby I'm not able to include a header file into a PHP file

In the code below, I've removed the original content as it's quite big & anyway what the code does is irrelevant to including the header file

MAIN.PHP

        <?php
 php content
            ?>


            <html>
    <head>  
            </head>
                <body >
                <div>
                   header content
                    </div>

                    <br/>
                    <div>
                </div>
                </body>
            </html>

I would like to have the following code in the header.php file & include it on all pages.

            <div>
header content
</div>

When I do so with the main.php file looking as below, the page draws blank.

      <?php
 php content
            ?>


            <html>
    <head>  
            </head>
                <body >
                <div>
                   <? php include('header.php') ?>
                    </div>

                    <br/>
                    <div>
                </div>
                </body>
            </html>

I've tried debugging this & following a few solutions on stackoverflow, but evidently have failed to achieve what I'm after.

Could I please request a second pair of eyes to help me spot the problem?

  • 写回答

1条回答 默认 最新

  • duanchai0028 2015-12-28 08:49
    关注

    Well, first of all, I don't think you copied the code correctly to here. As my debugging eyes can see, you got 2 issues:

    1. Line 1: < is missing at the start. Change it to <?php. (Maybe copy paste error?)
    2. <?php include('header.php'); is missing closing tag. Change it to: <?php include('header.php'); ?>

    If you get a blank page, you probably have some errors. Try finding the "error.log" file in you working directory or add the following code at the start of the page:

    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下