$string = "
put returns between paragraphs
for linebreak add 2 spaces at end
";
Run Code Online (Sandbox Code Playgroud)
想要从字符串中删除所有新行.
我有这个正则表达式,它可以捕获所有这些,问题是我不知道我应该使用哪个函数.
/\r\n|\r|\n/
Run Code Online (Sandbox Code Playgroud)
$string 应成为:
$string = "put returns between paragraphs for linebreak add 2 spaces at end ";
Run Code Online (Sandbox Code Playgroud) 我明白那个:
'\n' // literally the backslash character followed by the character for lowercase n
"\n" // interpreted by php as the newline character
Run Code Online (Sandbox Code Playgroud)
但对于我的生活,我无法理解为什么'\n' === '\\n'.在我看来,'\\n'将等于三个单独的字符:两个单独的反斜杠,后跟字母n.
'\n' === '\\n'PHP中的原因是什么?