Php 无法在浏览器中返回html字符串
我构建了一个html字符串,用于两个目的:Php 无法在浏览器中返回html字符串,php,return,concatenation,Php,Return,Concatenation,我构建了一个html字符串,用于两个目的: 输出到浏览器 以完全格式化的电子邮件发送 此脚本非常适合发送电子邮件,但不适合在浏览器中输出数据。以下是基本构建: function makeformatedmessage(){ $message = ''; $message .= ' <html> <head> <title>Some title</title> </head> <body>';
function makeformatedmessage(){
$message = '';
$message .= '
<html>
<head>
<title>Some title</title>
</head>
<body>';
$message .='complex html body';
$message .='complex html body 2';
$message .='</body>
</html>';
return $message;
}
函数makeFormattedMessage(){
$message='';
$message.='
一些头衔
';
$message.='complex html body';
$message.='complex html body 2';
$message.='
';
返回$message;
}
当我将此作为电子邮件发送时,所有内容都已发送,但当我仅将$message输出到浏览器时,='complex html body 2'部分消息丢失。是否有更好的方法存储html并输出到浏览器
已编辑
通过仔细调试,我发现有另一个文件具有在浏览器中调用的相同功能。在我将其移除后,它正常工作。当我运行时:
<?php
function makeformatedmessage(){
$message = '';
$message .= '
<html>
<head>
<title>Some title</title>
</head>
<body>';
$message .='complex html body';
$message .='complex html body 2';
$message .='</body>
</html>';
return $message;
}
echo makeformatedmessage();
?>
“我的浏览器”的源输出(如预期)为:
一些头衔
复杂html正文复杂html正文2
您如何在浏览器中显示它?您可能需要发布“复杂的html正文”。我现在无法测试,但我几乎可以肯定这个特定的示例(echo makeformatedmessage();
)可以正常工作;
<html>
<head>
<title>Some title</title>
</head>
<body>complex html bodycomplex html body 2</body>
</html>