Ara*_*ran 4 php arrays variables explode
我试图使用explode函数将字符串分解为数组.
我希望它使用字符串中找到的换行符来打破字符串.
我查了一下,我尝试了所有的方法,但我无法让它工作.
这是我到目前为止:
$r = explode("\r\n" , $roster[0]);
Run Code Online (Sandbox Code Playgroud)
但是当我var_dump变量时,我得到以下内容:
array (size=1)
0 => string '\r\n ( G A Sh Hi Ga Ta PIM, +\/- Icetime Rating)\r\nR Danny Kristo 1 0 2 0 0 0 0 1 7.00 7\r\nR Brian Gionta 1 1 5 1 1 0 0 0 19.20 8\r\nR Steve Quailer...
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
Luc*_*ert 15
您可以尝试使用正则表达式拆分字符串.换行符有一个类:
$r = preg_split('/\R/', $string);
Run Code Online (Sandbox Code Playgroud)
编辑:向正则表达式和函数参数添加缺少的分隔符.
问题是\r\n在原始文本中不是行符号的结尾 - 它只是字面上的'反斜杠-r-反斜杠-n'序列.因此,您需要考虑到这一点:
$r = explode('\r\n', $roster[0]);
Run Code Online (Sandbox Code Playgroud)
...即,使用单引号来分隔字符串.