所以作为一个新手,这只是一个最佳实践问题,但最好从这样的函数返回 html:
function returnHtml($userName)
{
$htmlMsg = "
<html>
<head>
<title>Return the html</title>
</head>
<body>
<p>You've received an email from: ".$userName.".</p>
</body>
</html>
";
return $htmlMsg;
}
或者像这样:
function returnHtml($userName)
{
?>
<html>
<head>
<title>Return the html</title>
</head>
<body>
<p>You've received an email from: <?php $userName ?>.</p>
</body>
</html>
<?php
}
第二个比第一个容易得多,因为您不必将 html 转换为字符串,但我想知道缺少 return 语句是否会导致任何无法预料的问题。感谢您的任何建议!