2011-02-09 62 views
0

我一直試圖通過將我的網站結構定義爲php字符串變量來清理我的網站,然後將這些變量回顯出來。這將我所有的站點結構壓縮到五行,並在回聲語句之間添加一篇文章。我的頁面看起來是這樣的:將PHP包含在包含語句的字符串中得到迴應

< PHP
包括( '模塊/ moddefault.php');? //鏈接到設置爲變量的網站結構
$ title =「示例頁面」; //定義頁面標題。這被插入到嵌入式標題語句中。

echo「$ modtop」; //聲明,標題,頭銜等
echo「$ precontent」; //預內容結構
?>

<H1> Web內容放在這裏</H1 >
<p>文章內容將是很好,整潔。 </p >

<?php echo「$ postcontent」; // Post-Content Structure
? >

我想知道如何嵌入我的CSS包含PHP字符串變量的內部。 PHP包括不要註冊,因爲PHP已經處理了頁面。包含語句正在打印到我的屏幕上,而不是作爲php語句處理。

這裏是我在前面的代碼塊回聲的變量之一的一個示例:

$ precontent =「<體>」;
$ precontent。=「< div id ='wrapper'>」;
$ precontent。=「< div id ='header'>」;
$ precontent。=「<div>」;
$ precontent。=「include'modules/header.inc'」; //這是我遇到麻煩的地方
$ precontent。=「</div >」;
$ precontent。=「</div >」;
$ precontent。=「< div id ='navtop'>」;
$ precontent。=「<div>」;
$ precontent。=「include('modules/topnav.inc');」; //這是我遇到麻煩的地方
$ precontent。=「</div >」;
$ precontent。=「</div >」;
$ precontent。=「< div id ='centerbox'>」;
$ precontent。=「< div id ='article'>」;
$ precontent。=「< div id ='innerarticle'>」;
$ precontent。=「<div>」; 。

我試圖在字符串中嵌入另一個PHP語句,

$ precontent = 「?< PHP的包括:( '模塊/ topnav.inc' ;? >」; 這不起作用。

我也曾嘗試SSI格式,但是PHP似乎因爲他們的忽略語句中寫到忽略這些語句。

任何幫助都會很棒。

回答

1

你試過$precontent.=file_get_contents('modules/header.inc');

+0

這一工程!謝謝噸。 – jen03017 2011-02-09 22:25:53

0

爲什麼沒有這樣的:

header.inc: 

    <html> 
    <head> 
     <title><?php echo $page_title ?></title> 
    </head> 

    <body> 
    [--- common page content here, e.g. menus ---] 

footer.inc: 

    [---common page footer stuff here, eg. copyright lines ---] 
    <p><?php echo $page_footer ?></p> 
    </body> 
    </html> 

,然後你就必須

article1.php: 

<?php 
    $page_title = "This is page 1"; 
    $page_footer = "Thanks for reading this"; 
    include_once('header.inc'); 
?> 
<p>This is the content of page #1</p> 
<?php 
    include_once('footer.inc'); 
?>