【问题标题】:Embedding PHP include statements within a string that gets echoed将 PHP 包含语句嵌入到回显的字符串中
【发布时间】:2011-06-24 11:35:44
【问题描述】:

我一直在尝试通过将我的站点结构定义为 php 字符串变量然后将这些变量回显来清理我的站点。这将我所有的站点结构压缩到五行,在 echo 语句之间有一篇文章。我的页面如下所示:

包括('modules/moddefault.php'); //链接到站点结构设置为变量
$title = "示例页面"; // 定义页面标题。这被插入到嵌入的标题语句中。

echo "$modtop"; // 声明、头部、标题等
回声“$precontent”; // 前置内容结构
?>

网络内容放在这里


文章内容会很好,整洁。

?>

我想知道如何将我的 CSS 包含在 PHP 字符串变量中。 PHP 包含不要注册,因为 php 已经处理了页面。包含语句正在打印到我的屏幕上,而不是作为 php 语句处理。

这是我在上一个代码块中回显的变量之一的示例:

$precontent = "

";
$precontent .= "
";
$precontent .= "";
$precontent .= "";
$precontent .= "
";
$precontent .= "
";
$precontent .= "
";
$precontent .= "
";

我尝试在字符串中嵌入另一个 php 语句,

$precontent .= ""; 这没有用。

我也尝试过 ssi 格式,但是 php 似乎忽略了这些语句,因为它们是写在忽略语句中的。

任何帮助都会很棒。

【问题讨论】:

    标签: php include embedding modularization


    【解决方案1】:

    为什么没有类似的东西:

    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');
    ?>
    

    【讨论】:

      【解决方案2】:

      你试过$precontent.=file_get_contents('modules/header.inc');

      【讨论】:

        猜你喜欢
        • 2013-11-13
        • 1970-01-01
        • 2011-03-22
        • 2016-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-07
        • 1970-01-01
        相关资源
        最近更新 更多