3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $string = 'Date: 2017-07-06 14:37:22 Name: BTC - amount: 0.01106513 - earned: 0.00000001 - rate: 35% Date: 2017-07-06 14:37:21 Name: BTC - amount: 0.08750203 - earned: 0.00000005 - rate: 35% Date: 2017-07-06 14:30:52 Name: BTC - amount: 0.09555558 - earned: 0.00015358 - rate: 34.49%'; $lines = explode(PHP_EOL, $string); $days = []; foreach($lines as $line) { $match = preg_match('/Date\:\s([0-9]+\-[0-9]+\-[0-9]+)\s([^\s]+)\sName\:\s([a-zA-Z0-9]+)\s\-\samount\:\s([0-9\.]+)\s\-\searned\:\s([0-9\.]+)\s\-\srate\:\s([0-9\.\%]+)/i', $line, $matches); print_r($matches); $date = $matches[1]; $time = $matches[2]; $name = $matches[3]; $amount = $matches[4]; $earned = $matches[5]; $rate = $matches[6]; if(!isset($days[$date])) { $days[$date] = []; } $days[$date][] = [ 'date' => $date, 'name' => $name, 'amount' => $amount, 'earned' => $earned, 'rate' => $rate, 'time' => $time ]; } print_r($days);