gpt4 book ai didi

php - 从 php 文件中获取 HTML 内容,在它被处理之后

转载 作者:太空狗 更新时间:2023-10-29 15:30:41 24 4
gpt4 key购买 nike

我想获取 HTML 格式的 php 文件的内容。我将其用作 HTML 电子邮件模板,但需要用我的数据库中的动态数据填充它。

我试过了

file_get_contents('/emails/orderconfirm.php'); 

但这只是在服务器将其处理为 HTML 之前返回 php 代码。

我猜这真的很简单?任何想法将不胜感激。

谢谢

最佳答案

为了执行您的emails/orderconfirm.php 中的特定代码,您需要include它的内容。

包含的内容将被编译和呈现。
但是,你只要echo

就可以得到内容

这样,您需要使用 ob_start()图书馆。

这是一个用法示例:

ob_start(); //Init the output buffering
include('emails/orderconfirm.php'); //Include (and compiles) the given file
$emailContent = ob_get_clean(); //Get the buffer and erase it

编译后的内容现在存储在您的 $emailContent 变量中,您可以按照自己的方式使用它。

$email->body = $emailContent;

关于php - 从 php 文件中获取 HTML 内容,在它被处理之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13954791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com