“期间”是什么意思?字符 (.) 如果用在 PHP 字符串中间是什么意思?
下面是一些示例代码:
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
字符串每段中间的句点字符有何作用?
例如,
"blabla" . "blabla" . "blablalba";
Here is some example code:
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
What does the period character do in the middle of each piece of the string?
For example,
"blabla" . "blabla" . "blablalba";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该运算符用于组合字符串。
编辑
嗯,更具体地说,如果一个值不是字符串,则必须将其转换为字符串。请参阅转换为字符串了解更多细节。
不幸的是,它有时会被误用,导致内容变得难以阅读。以下是不错的用法:
这里我们组合了函数的输出。这没关系,因为我们没有办法使用标准内联字符串语法来做到这一点。不正确使用它的几种方法:
这里,您有一个名为
$result
的变量,我们可以将其内联到字符串中:另一个难以发现的误用是:
如果您这样做,这有点棘手不知道内联变量的
{}
转义序列:关于引用的示例:
这有点诡计,因为如果我们不使用串联运算符,我们可能会通过以下方式发出换行符:事故,所以这迫使线路结束改为“\r\n”。由于电子邮件标头的限制,我认为这是一个更不寻常的情况。
请记住,这些连接运算符会打破字符串,使内容变得难以阅读,因此仅在必要时使用它们。
This operator is used to combine strings.
EDIT
Well, to be more specific if a value is not a string, it has to be converted to one. See Converting to a string for a bit more detail.
Unfortunately it's sometimes mis-used to the point that things become harder to read. Here are okay uses:
Here we're combining the output of a function. This is okay because we don't have a way to do this using the standard inline string syntax. A few ways to improperly use this:
Here, you have a variable called
$result
which we can inline in the string instead:Another hard to catch mis-use is this:
This is a bit tricky if you don't know about the
{}
escape sequence for inlining variables:About the example cited:
This is a bit tricker, because if we don't use the concatenation operator, we might send out a newline by accident, so this forces lines to end in "\r\n" instead. I would consider this a more unusual case due to restrictions of email headers.
Remember, these concatenation operators break out of the string, making things a bit harder to read, so only use them when necessary.
这是连接运算符。它将两个字符串连接在一起。例如:
It's the concatenation operator. It joins two strings together. For example:
这是连接运算符,将两个字符串连接在一起(将一个字符串从两个单独的字符串)。
It's the concatenation operator, concatenating both strings together (making one string out of two separate strings).