PHP - 从另一个文件加载标题 [英] PHP - Load header from another file

查看:90
本文介绍了PHP - 从另一个文件加载标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题,因为我无法将头文件包含到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>

我想在 header.php中包含以下代码 code> file&将它包含在所有页面中。

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

            <div>
header content
</div>

当我使用 main.php

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>

我试过调试这个&以下几种解决方案在stackoverflow上,但显然未能实现我所追求的。

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?

推荐答案

嗯,首先,我认为你没有把代码正确地复制到这里。
正如我的调试眼光所看到的那样,您有两个问题:

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. 第1行:< 在开始时缺失。将其更改为<?php 。 (也许
    复制粘贴错误?)
  2. <?include('header.php'); is missing关闭标签。将其更改为:
    <?php include('header.php'); ?>

  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'); ?>

如果您有空白页面,您可能会遇到一些错误。尝试在您的工作目录中找到error.log文件,或者在页面开始处添加以下代码:

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);

这篇关于PHP - 从另一个文件加载标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆