@ 2019-06-28T05:38:41Z <?php
$str = <<<'EOF'
text 16.11 19.22 21.33
text 17.11 23.22 25.33 27.55
text 18.11 26.22
EOF;
echo 'Если не завязываться на количестве пробелов: ', PHP_EOL;
$res = [];
$lines = preg_split('#[\n\r]+#', trim($str));
foreach ($lines as $line) {
$prices = preg_split('#\s+#', $line);
$key = array_shift($prices);
$res[] = ['key' => $key, 'prices' => $prices];
}
echo json_encode($res), PHP_EOL;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.1.25 - 7.1.30 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Если не завязываться на количестве пробелов:
[{"key":"text","prices":["16.11","19.22","21.33"]},{"key":"text","prices":["17.11","23.22","25.33","27.55"]},{"key":"text","prices":["18.11","26.22"]}]
preferences:dark mode live preview
176.87 ms | 403 KiB | 167 Q