相关疑难解决方法(0)

从字符串中删除新行并替换为一个空格

$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)

php regex string

269
推荐指数
11
解决办法
43万
查看次数

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

我明白那个:

'\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中的原因是什么?

php string newline

6
推荐指数
2
解决办法
150
查看次数

标签 统计

php ×2

string ×2

newline ×1

regex ×1