Reputation: 7128
I don't even know what should I call this type of data but I need to get array out of it.
$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",
]
any idea?
I changed my code to:
$folders = preg_split("/[\s,]+/", $folderss);
Now I'm getting:
array:4 [▼
0 => "DO_NOT_UPLOAD_HERE"
1 => "domains"
2 => "public_html"
3 => ""
]
I have 1 extra row there, how to remove it?
If I use
$folders = explode("\n", $folderss);
same result as using preg_split
happens (extra line)
array:4 [▼
0 => "DO_NOT_UPLOAD_HERE"
1 => "domains"
2 => "public_html"
3 => ""
]
Upvotes: 0
Views: 61
Reputation: 190
Try this to remove empty values from array
$folders = preg_split("/[\s,]+/", $folderss);
$folders=array_filter($folders);
Upvotes: 1
Reputation: 6388
You can use array_filter
to remove the empty values from an array
$folders = array_filter(preg_split("/[\s,]+/", $folderss));
Upvotes: 0
Reputation: 4750
Replace this line:
$folders = explode(',', $folderss);
by:
$folders = explode('\n', trim($folderss, '"');
Upvotes: 0