So being a newb, this is just a best practices question but is it better to return html from a function like this:
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;
}
Or like this:
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
}
The second one is much easier than the first since you don’t have to turn the html into a string, but I’m wondering if the lack of a return statement would cause any unforeseen problems. Thank you for any advice!
The two functions you’ve posted do different things. The first returns a string of html, the second prints the string.
Essentially it depends on what you want to accomplish with the function. If you want to print some HTML, the second function is better, if you want to have some HTML in a string, the first is better.