注意:很抱歉,如果这是一个非常简单的问题,但是我对代码的格式有些强迫。
我有一个类,该类具有返回字符串的函数,该字符串将构成电子邮件的正文。我希望此文本经过格式化,以便它在电子邮件中看起来很正确,而且也不会使我的代码显得时髦。这就是我的意思:
class Something
{
public function getEmailText($vars)
{
$text = 'Hello ' . $vars->name . ",
The second line starts two lines below.
I also don't want any spaces before the new line, so it's butted up against the left side of the screen.";
return $text;
}
}
但也可以写成:
public function getEmailText($vars)
{
$text = "Hello {$vars->name},\n\rThe second line starts two lines below.\n\rI also don't want any spaces before the new line, so it's butted up against the left side of the screen.";
return $text;
}
但是换行和退货有什么关系呢?有什么不同?是\n\n
相当于\r\r
或\n\r
?在行与行之间创建行距时应该使用哪个?
然后是输出缓冲和heredoc语法的选项。
您如何处理在对象中使用长的多行字符串?