[英]php include file doesnt work
我做了header.php文件,我想将它包括在index.php文件中。
<body id="home">
<section class="container-fluid">
<div class="content row">
<section class="main col col-lg-8 col-sm-8">
<?php include"_/components/php/header.php"; ?>
</section><!--main -->
<section class="sidebar col col-lg-4 col-sm-4">
</section><!--sidebar -->
</div><!-- content -->
</section><!-- container -->
但是当显示页面时它无法正常工作..
<section class="main col col-lg-8 col-sm-8">
<!--?php include"_/components/php/header.php"; ?-->
</section>
使用include 'blabla.php';
或include('blabla.php');
(带空格或方括号)。 如果仍然无法正常工作,那么您要包含的主要php文件中肯定存在问题。
问题
首先,将页面移到本地服务器文件夹,以便服务器可以解析 PHP
并生成HTML..then:
<?php include"_/components/php/header.php";
/* ^^ add space here */ ?>
解决方案:
<?php include "_/components/php/header.php"; /* with space*/ ?>
另外,如果您的页面包含classes
或什至是通用的通用HTML,最好使用include_once
!
只需使用这个。
include("header.php");
您不必要求在参数中提供public_html /简单给出文件名的完整路径,您可以将头文件放在“ public_html / header.php”位置
您可以如下给出根目录的完整路径
<?php include $_SERVER['DOCUMENT_ROOT]."some_folder/components/php/header.php"; ?>
如果您在根目录中有文件夹,那么这里有一些_folder是可选的。 在此输入名称作为组件
$_SERVER['DOCUMENT_ROOT]
将为您提供根目录的路径(public_html)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.