简单,是吧?嗯,这是行不通的:-\
$skuList = explode('\n\r', $_POST['skuList']);
简单,是吧?嗯,这是行不通的:-\
$skuList = explode('\n\r', $_POST['skuList']);
当前回答
这个方法对我来说总是有效的:
$uniquepattern="@#$;?:~#abcz"//Any set of characters which you dont expect to be present in user input $_POST['skuList'] better use atleast 32 charecters.
$skuList=explode($uniquepattern,str_replace("\r","",str_replace("\n",$uniquepattern,$_POST['skuList'])));
其他回答
涵盖所有情况。不要依赖于您的输入来自Windows环境。
$skuList = preg_split("/\\r\\n|\\r|\\n/", $_POST['skuList']);
or
$skuList = preg_split('/\r\n|\r|\n/', $_POST['skuList']);
PHP_EOL表面上用于以跨平台兼容的方式查找换行符,因此它可以处理DOS/Unix问题。
试试这个:
$myString = "Prepare yourself to be caught
You in the hood gettin' shot
We going throw hell of blows
got my whole frame froze";
$myArray = explode(PHP_EOL, $myString);
print_r($myArray);
你试过用双引号吗?
这个方法对我来说总是有效的:
$uniquepattern="@#$;?:~#abcz"//Any set of characters which you dont expect to be present in user input $_POST['skuList'] better use atleast 32 charecters.
$skuList=explode($uniquepattern,str_replace("\r","",str_replace("\n",$uniquepattern,$_POST['skuList'])));
虽然不完美,但我认为这是最安全的。添加nl2br:
$skuList = explode('<br />', nl2br($_POST['skuList']));