gpt4 book ai didi

php - 为什么 '\n' === '\\n' 在 php 中是真的?

转载 作者:可可西里 更新时间:2023-11-01 13:08:45 25 4
gpt4 key购买 nike

我的理解是:

'\n' // literally the backslash character followed by the character for lowercase n
"\n" // interpreted by php as the newline character

但对于我来说,我无法理解为什么 '\n' === '\\n'。在我看来,'\\n' 等于三个单独的字符:两个单独的反斜杠,后跟字母 n。

为什么 '\n' === '\\n' 在 PHP 中为真?

最佳答案

来自手册(section on single quoted strings):

To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash, double it (\\). All other instances of backslash will be treated as a literal backslash

所以在单引号字符串中 \n 是两个字符,但是 \\n 是一个文字反斜杠后跟字母 'n' - 即相同的两个字符.

关于php - 为什么 '\n' === '\\n' 在 php 中是真的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11302721/

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