Example Text: This will be stored in the $_POST['x'] variable
This is sentence one.
This is sentence two.
This is sentence three.
如果我运行下面的代码,它将返回一个只有一个元素的数组
$x= mysqli_real_escape_string($db, $_POST['x']);
$y= preg_split("/(\r\n|\n|\r)/", $x);
但是如果我运行下面的代码,它将正确地将其拆分为所有 3 个元素。
$x = $_POST['x'];
$y= preg_split("/(\r\n|\n|\r)/", $x);
有其他人经历过这种现象吗?为什么会发生这种情况?
最佳答案
http://php.net/mysqli-real-escape-string
Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
这意味着换行符变为 \\n
(LF)、\\r
(CR) 和 \\r\\n
(CRLF) )。因此它们不再匹配正则表达式。
将来,RTM ;)
关于php - mysqli_real_escape_string 阻止 preg_split 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14926545/