<?php $str = '#PROGRAM "Accounting company" 98.2 #GENERATED 2020715 "SE"'; $quoted = false; $index = 0; $data = []; $rows = explode("\n", $str); $isPreviousSpace = false; foreach ($rows as $row) { $temp = []; $index = 0; $isPreviousSpace = false; for ($i = 0; $i < strlen($row); $i++) { if ($row[$i] === "\"") $quoted = !$quoted; if ($row[$i] === " " && !$quoted) { if (!$isPreviousSpace) { $temp[$index] = $temp[$index] ?? ""; $index++; } $isPreviousSpace = true; continue; } $isPreviousSpace = false; $temp[$index] = ($temp[$index] ?? "") . $row[$i]; } $data[] = $temp; } var_dump($data);
You have javascript disabled. You will not be able to edit any code.