Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP包括不工作_Php_Html_Include - Fatal编程技术网

PHP包括不工作

PHP包括不工作,php,html,include,Php,Html,Include,我试图将PHP的include函数与html结合使用,但它不起作用。我只是在摆弄标签,看起来很简单,但我不明白为什么它不起作用 以下是template.php页面: <!DOCTYPE html> <html> <head> <title>Template</title> <link href="css/layout.css" type="text/css" rel="st

我试图将PHP的include函数与html结合使用,但它不起作用。我只是在摆弄标签,看起来很简单,但我不明白为什么它不起作用

以下是template.php页面:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Template</title>
        <link href="css/layout.css"  type="text/css" rel="stylesheet" />
    </head>
    <body>

      <div id="wrapper">

          <?php 
           include ("include/header.php");
           include ("include/leftcolumn.php"); 
           include ("include/rightcolumn.php"); 
           include ("include/footer.php"); 
           ?> 

     </div>


    </body>
    </html>

样板
下面是我试图包含的header.php页面:


标题

我唯一能想到的是错误的目录,我有一个include文件夹,它是header.php所在的位置,并在include标记中引用了它……除非我错了,有什么提示吗?谢谢

您不需要使用括号,请尝试:

<?php 
           include "include/header.php";
           include "include/leftcolumn.php"; 
           include "include/rightcolumn.php"; 
           include "include/footer.php"; 
           ?> 

并确保路径正确

编辑:

php手册上的每个示例都没有括号


还有一个问题。在这里,您可以执行您的php文件。只是在浏览器中或使用任何wamp服务器应用程序来模拟php的服务器端操作?

我没有测试您的代码,但请确保您的路径(您的template.php文件是否在include文件夹之前到达根目录?)(说起来很疯狂,但路径问题很常见,很容易让您发疯)

或者,也可以尝试以下语法: include
'include/footer.php'

删除括号()


样板

我正要回答同样的问题+1您能详细说明一下吗?我不会说土耳其语,所以我不知道翻译人员是否编造了一些东西,但原始的英文版本只说:“不需要括号”(不是“禁止使用括号”)。我只想知道他/她是如何执行php文件的。在浏览器上?或者使用类似xampp的应用程序?它到底是如何工作的?它会显示一条错误消息吗?PHP标记没有被解析?计算机爆炸了?那么原始代码有什么问题?另外,您声称删除
include
语句的可选括号会改变其行为,您能详细说明一下吗?我已删除()并将语法更改为“include/footer.php”;我仍然没有任何运气。手册本身显示使用括号并不是最好的解决方案,我不知道原始代码中到底是什么问题,很想知道它!问题是什么?为什么去掉括号可以解决?你有一个语法问题。请浏览下面提到的PHP手册链接。显然,你的困惑会变成自信。:)保重。
<!DOCTYPE html>
    <html>
    <head>
        <title>Template</title>
        <link href="css/layout.css"  type="text/css" rel="stylesheet" />
    </head>
    <body>

      <div id="wrapper">

          <?php 
    // removing brackets... hopefully it will be working....
           include "include/header.php";
           include "include/leftcolumn.php"; 
           include "include/rightcolumn.php"; 
           include "include/footer.php"; 
           ?> 

     </div>


    </body>
    </html>