问题描述
可能的重复:
在 HEREDOC 字符串中调用 PHP 函数
我正在使用 Swiftmailer PHP 创建一个订单完整页面.当客户登陆此页面时,我使用包含到 PHP 文件.
I am using Swiftmailer PHP to create an order complete page. When the customer lands on this page, I use an include to a PHP file.
此页面文件包含发送给客户的 SwiftMailer EOM HTML.但是,我有分块的 HTML 部分,因此标题是通过名为 header 的函数实现的,并且订单总数也相同.我希望能够在 EOM 中包含 EOM 函数.这可能吗?
This page file has SwiftMailer EOM HTML that gets sent to the customer. However I have the HTML parts in chunks, so the header is via a function called header and order totals are the same too. I want to be able to include EOM functions inside the EOM. Is this possible?
Id = 46088;
// MAIL FUNCTION
function mailToSend($Id){
// EOM CAN'T BE TABBED
$html = <<<EOM
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
getHeader($Id);
getOrderTotalBoxTable($Id);
</body>
</html>
EOM;
}
mailToSend(46088);
推荐答案
就像@deceze 说的,你不能,但这会起作用(将@xenon 评论扩展到一个例子):
Like @deceze said, you can't, but this will work (extend @xenon comment to an example):
function getHeader($Id = '')
{
$text = '';
$text.=' Your first line of text, store it in an variable <br>';
$text.= 'Hello '.$Id.'<br>';
$text.='Your last text to be returned<br>';
return $text;
}
// MAIL FUNCTION
function mailToSend($Id){
$getHeader = getHeader($Id);
$getOrderTotalBoxTable = getOrderTotalBoxTable($Id);
// EOM CAN'T BE TABBED
$html = <<<EOM
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
$getHeader;
$getOrderTotalBoxTable;
</body>
</html>
EOM;
}
mailToSend(46088);
这篇关于PHP 为什么 EOM 不能包含 PHP 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!