2017-02-11 111 views
-3

我想使用PHP的包括函數與HTML結合,但它不工作。我只是瞎搞與標籤,它似乎很簡單,但我想不出爲什麼它不工作...PHP包括不工作

這裏是的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頁面:

<header> 
<p>Header.</p> 
</header> 

我能想到的唯一的事情是錯誤的目錄,我有一個包含文件夾是在header.php文件是和在引用了包括標籤...除非我錯了,任何提示?由於

directory folder image

+0

它究竟如何不起作用?它顯示一條錯誤消息? PHP標籤沒有被解析?電腦爆炸了? –

回答

1

http://php.net/manual/en/function.include.php 你不需要使用括號嘗試:

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

,並確保正確的路徑。

編輯:

在PHP曼努埃爾是不要有括號每爲例。

還有一個問題。在那裏你試圖執行你的PHP文件。只是在瀏覽器中或使用任何wamp服務器應用程序來模擬您的php的服務器端操作?

+0

我剛要回答同樣的事情+1 – SaggingRufus

+0

你能詳細解釋一下嗎?我不會說土耳其語,所以我不知道譯員是否編寫了一些東西,但原來的英文版只說:「不需要括號」(不是「括號被禁止」)。 –

+0

我只是想知道他/她如何執行php文件。在瀏覽器上?或使用xampp像應用程序? – Ahmet

0

我沒有測試過你的代碼,但要確定你的路徑(你的template.php文件是根文件夾,在包含文件夾之前?)(這很瘋狂,但是路徑是一個常見問題,而且它可以很容易使你瘋了)

或者,試試這個語法太: 包括'include/footer.php';

+0

那麼原始代碼中的問題是什麼?另外,你聲稱刪除'include'語句的可選括號會改變它的行爲 - 你能詳細說明一下嗎? –

+0

我已刪除()並將語法更改爲'include/footer.php';我仍然沒有任何運氣.. – gwen

+0

手冊本身顯示使用括號不是最好的解決方案http://php.net/manual/en/function.include.php#function.include,我不知道到底是什麼在原代碼中出現問題,好奇地知道它! – idkn

0

刪除您的括號()

<!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> 
+0

問題是什麼,爲什麼刪除括號可以修復它? –

+0

你有一個語法問題。請通過下面提到的PHP手冊鏈接。顯然你的困惑會變得自信。 :) 保重。 http://php.net/manual/en/function.include.php –

0

刪除空間

include("include/header.php");