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); $date = $matches[0]; $time = $matches[1]; $name = $matches[2]; $amount = $matches[3]; $earned = $matches[4]; $rate = $matches[5]; if(!isset($days[$date])) { $days[$date] = []; } $days[$date][] = [ 'date' => $date, 'name' => $name, 'amount' => $amount, 'earned' => $earned, 'rate' => $rate, 'time' => $time ]; } print_r($days);
Output for 7.1.7
Array ( [Date: 2017-07-06 14:37:22 Name: BTC - amount: 0.01106513 - earned: 0.00000001 - rate: 35%] => Array ( [0] => Array ( [date] => Date: 2017-07-06 14:37:22 Name: BTC - amount: 0.01106513 - earned: 0.00000001 - rate: 35% [name] => BTC [amount] => 0.01106513 [earned] => 0.00000001 [rate] => 35% [time] => 2017-07-06 ) ) [Date: 2017-07-06 14:37:21 Name: BTC - amount: 0.08750203 - earned: 0.00000005 - rate: 35%] => Array ( [0] => Array ( [date] => Date: 2017-07-06 14:37:21 Name: BTC - amount: 0.08750203 - earned: 0.00000005 - rate: 35% [name] => BTC [amount] => 0.08750203 [earned] => 0.00000005 [rate] => 35% [time] => 2017-07-06 ) ) [Date: 2017-07-06 14:30:52 Name: BTC - amount: 0.09555558 - earned: 0.00015358 - rate: 34.49%] => Array ( [0] => Array ( [date] => Date: 2017-07-06 14:30:52 Name: BTC - amount: 0.09555558 - earned: 0.00015358 - rate: 34.49% [name] => BTC [amount] => 0.09555558 [earned] => 0.00015358 [rate] => 34.49% [time] => 2017-07-06 ) ) )