$file <==\n$line\n\n"; // Extract current step [123/456] if (preg_match('/\[\d+\/\d+\]/', $line, $m)) { $step = $m[0]; } } echo json_encode([ 'output' => $output, 'step' => $step ]);