gpt4 book ai didi

\r\n 和\n 之间的 PHP 区别

转载 作者:IT王子 更新时间:2023-10-29 00:11:21 26 4
gpt4 key购买 nike

简单的问题...

我看到有人告诉我在不同的地方使用“\r\n”,而其他人告诉我在同一个地方使用“\n”。我确定一个是对的,一个是错的。示例 - 设计 mail() header 时:

教程 #1:

//define the headers we want passed. Note that they are separated with \r\n 
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

教程 #2(注意 header 参数):

mail($to, $subject, $body, 
"From: " . $from . "\n" .
"bcc: " . $bcc . "\n" .
"MIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=" . $mime_boundary_header)

我很困惑,但显然它有所不同,因为对于一个,我的标题有效,而对于另一个,它们只是有时有效。

最佳答案

\r\n 是 Windows 系统的行尾字符。

\n 是 UNIX 系统的行尾字符。

这些字符是不可见的。根据我自己的经验,\n 通常也适用于 Windows。

有些人喜欢使用 PHP_EOL常量而不是这些字符以实现平台之间的可移植性。

echo 'hi' . PHP_EOL;
echo "hi\n";

$headers = "From: webmaster@example.com" . PHP_EOL
. "Reply-To: webmaster@example.com";

关于\r\n 和\n 之间的 PHP 区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2115549/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com