将PHP页面的html响应返回到变量 [英] Return html response from PHP page in to variable
问题描述
我正在尝试生成一个通过另一个PHP文件创建的HTML的电子邮件。
I am trying to generate an email with some HTML that is created via another PHP file.
电子邮件生成文件由每个小时运行的cron运行。
生成电子邮件所需HTML的另一个文件。
Email generating file is run by a cron running every hour. Another file exists that generates the HTML required for the email.
HTML生成文件没有可以调用的功能,例如: p>
The HTML generating file does not have a function that I can call, for instance:
$emailBody = generateHTML($id);
HTML生成文件旨在包含在希望显示HTML的页面上,实例:
The HTML generating file was designed to be included on a page that you wished to display the HTML, for instance:
include "htmlGenerator.php";
我的问题是:如何获取htmlgenerator.php文件返回到变量,准备好被推入电子邮件。
My question is: How can I get what the htmlgenerator.php file returns in to a variable, ready to be pushed in to an email.
如果这不清楚,抱歉,我很乐意回答任何问题。
Apologies if this is not very clear, I will be happy to answer any questions.
提前感谢!
推荐答案
如果我明白你说的话,可以使用输出缓冲,
,以便您可以获得 htmlGenerator.php $ c $的输出c>
If I understood what you said, you can use output buffering,
so that you can get the output of htmlGenerator.php
例如:
ob_start();
// as an example
echo "Hello World";
// or in our case
include "htmlGenerator.php";
$result = ob_get_contents();
ob_end_clean();
您还可以创建一个简单的函数:
You can also create a simple function like this:
function include_output($filename)
{
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
$mycontent = include_output("htmlGenerator.php");
阅读php文档了解更多详情。
Read the php documentation for further details.
这篇关于将PHP页面的html响应返回到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!