2014-01-29 72 views
0

我想從一個名爲包括網站名稱sitename.php我已經試過添加包括從外部文件

$thisPage='include "sitename.php" '; ?> 

,並得到錯誤報告。我還需要將文件添加到

include("../../../EngineerLocation/sitename.php"); 

代替的話網站名稱,我想包括來自PHP文件的網站名稱

+1

**網站名稱**如何存儲在** ** sitename.php? – 2014-01-29 19:19:24

+0

sitename.php只包含單詞COUNTY PRINT –

回答

0

您可以包括實際PHP文件:

// sitename.php 
<?php 
$thisPage = "Page Name"; 

// otherpage.php 
<?php 
include("sitename.php"); 
echo $thisPage; 

或者使用file_get_contents

// sitename.txt 
Page Name 
// otherpage.php 
<?php 
$thisPage = file_get_contents("sitename.txt"); 

要在網站名稱使用名稱的文件,請執行下列操作:

<?php 
$thisPage = file_get_contents("sitename.txt"); 
include("../../../EngineerLocation/{$thisPage}.php"); 
+0

<?php $ thisPage =「file_get_contents(sitename.php)」;?>試過這個,但它只在頁面頂部顯示了file_get_contents(sitename.php) –

+0

看起來很合理,但是第一個沒有顯示任何字詞報告顯示找不到文件,它與頁面 –

+0

位於同一個文件夾。對不起,我的錯誤是,文件名必須在引號內:'<?php $ thisPage = file_get_contents(「sitename.php」)。 「報告」;?>' – Ezequiel

0

嘗試:

include("$_SERVER[DOCUMENT_ROOT]/sitename.php"); 
+0

但是如何適合<?php $ thisPage =「Reports」; ?> –