- explode: documentation ( source)
- trim: documentation ( source)
- json_encode: documentation ( source)
<?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 = explode("\n", trim($str));
foreach ($lines as $line) {
[$key, $prices] = explode(" ", $line);
$prices = explode(' ', $prices);
$res[] = ['key' => $key, 'prices' => $prices];
}
echo json_encode($res), PHP_EOL;