Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 由新行分解-未知字符_Php_Newline - Fatal编程技术网

Php 由新行分解-未知字符

Php 由新行分解-未知字符,php,newline,Php,Newline,我有以下代码: $text = "Line 1 Line 3"; $n = explode("\r", $text); 如果我回显$n[1](第2行),我会得到一个空格。但是$n[1]==“返回false 那么角色是什么呢 更新: 经过进一步研究,我真的应该使用: $n = preg_split("/\r\n|\n|\r/", $text); 换行符可以是\n、\r或\r\n,具体取决于生成新行的操作系统和/或应用程序 请参见换行符可以是\n、\r或\r\n,具体取决于生成新行的操作系统

我有以下代码:

$text = "Line 1

Line 3";

$n = explode("\r", $text);
如果我回显
$n[1]
(第2行),我会得到一个空格。但是
$n[1]==“返回
false

那么角色是什么呢

更新: 经过进一步研究,我真的应该使用:

$n = preg_split("/\r\n|\n|\r/", $text);

换行符可以是
\n
\r
\r\n
,具体取决于生成新行的操作系统和/或应用程序


请参见换行符可以是
\n
\r
\r\n
,具体取决于生成新行的操作系统和/或应用程序


请参见

文本的新行是
\r\n
。因此,您的字符串是:

$text = "Line 1\r\n\r\nLine 3";
explode(“\r”,$text)
make:

array("Line 1","\n","\nLine 3");
并且
\n
不等于“”或“”

有关为什么有多个新线表示的历史原因,请参见:


文本的新行是
\r\n
。因此,您的字符串是:

$text = "Line 1\r\n\r\nLine 3";
explode(“\r”,$text)
make:

array("Line 1","\n","\nLine 3");
并且
\n
不等于“”或“”

有关为什么有多个新线表示的历史原因,请参见:


是的,我需要
$n=explode(“\r\n”,$text)
所以现在
$n[1]==“是的,我需要
$n=explode(“\r\n”,“$text”)所以现在
$n[1]==“”