簡體   English   中英

在PHP中包含其他文件中的文本

[英]Include text from other files in PHP

我想為我的網站創建電子郵件模板。

我的范本

所以說這是我的template_header.php

<html>
    <head>
        <title>
            '.$email_subject.'
        </title>
    </head>
    <body>

這是我的template_footer.php

    </body>
</html>

問題

據我所知,我可以使用輸出緩沖來包括這些模板。 這是我的代碼:

<?php
ob_start();
include "template_header.php";
?>
<p>Text</p>
<?php
include "template_footer.php";
$message = ob_get_contents();
ob_end_clean();
?>

但這不起作用! $message為空! 即使我執行var_export($message) ,我也var_export($message) !!! 甚至沒有一個空字符串。

  • 那么我的代碼有什么問題呢?
  • 我可以添加文字的其他方式有哪些?

這對我有用。

ob_start(); 
//print all the things - and I mean print. echoing and plain html work.
$message = ob_get_clean();

echo $message;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM