我什至不知道我应该怎么称呼这种类型的数据,但我需要从中取出数组。
$folderss = $ssh->exec($command);
$folders = explode(',', $folderss);
array:1 [▼
0 => """
DO_NOT_UPLOAD_HERE\n
domains\n
public_html\n
"""
]
array:3 [▼
0 => "DO_NOT_UPLOAD_HERE",
1 => "domains",
2 => "public_html",
]
有什么想法吗?
我将代码更改为:
$folders = preg_split("/[\s,]+/", $folderss);
现在我得到:
array:4 [▼
0 => "DO_NOT_UPLOAD_HERE"
1 => "domains"
2 => "public_html"
3 => ""
]
我那里还有1行,如何将其删除?
如果我使用
$folders = explode("\n", $folderss);
发生与使用preg_split
相同的结果(多行)
array:4 [▼
0 => "DO_NOT_UPLOAD_HERE"
1 => "domains"
2 => "public_html"
3 => ""
]
答案 0 :(得分:1)
尝试此操作从数组中删除空值
$folders = preg_split("/[\s,]+/", $folderss);
$folders=array_filter($folders);
答案 1 :(得分:0)
替换此行:
$folders = explode(',', $folderss);
作者:
$folders = explode('\n', trim($folderss, '"');
答案 2 :(得分:0)
您可以使用array_filter
从array
删除空值
$folders = array_filter(preg_split("/[\s,]+/", $folderss));