在html模板中解析PHP变量

在html模板中解析PHP变量,php,html,templates,Php,Html,Templates,我知道已经讨论过很多次了,但我找不到解决这个问题的办法 我有一个包含以下代码的PHP文件 if (file_exists("email.html")) { $message = file_get_contents("email.html"); } else { echo "No email.html file present"; return; } 在我的文件email.html中,我有如下内容: <p>Hello

我知道已经讨论过很多次了,但我找不到解决这个问题的办法

我有一个包含以下代码的PHP文件

if (file_exists("email.html")) {
        $message = file_get_contents("email.html");
    } else {
        echo "No email.html file present";
        return;
    }
在我的文件email.html中,我有如下内容:

  <p>Hello %recipient.UserName%, you receive this Email because you signed up at our site.</p>
您好%recipient.UserName%,您收到此电子邮件是因为您在我们的网站注册

变量$UserName在php文件中声明(在数组中)

当查看html文件输出时,我看到变量没有正确传递,并保持为%%

有什么建议吗?
谢谢

如果没有模板引擎,则不能使用
%%
或其他符号。对于您的问题,简单的方法是这样使用:

  <p>Hello <? = $recipient['UserName'] ?>, you receive this Email because you signed up at our site.</p>

将此更改为
文件\u get\u contents()
仅获取内容,它不会解析任何内容,因此如果您在获取内容后不自己进行解析,它将保持不变。是的,正确a忘记了这一点,我将编辑我的答案谢谢
ob_start();
include "email.html";
$message = ob_get_clean();