3v4l.org

run code in 300+ PHP versions simultaneously
<?php $lines = explode(PHP_EOL, "014-08-11 02:21:02:737 DEBUG Constructing Line Items 2014-08-11 02:21:02:739 ERROR [ActualLineItemCountMismatchEx] Doc Changed on Actual Line Item Count 2014-08-11 02:21:02:739 ERROR [ActualLineItemCountMismatchEx] 7 not equal to 2 2014-08-11 02:21:02:739 DEBUG Committing database transaction 2014-08-11 02:21:02:739 DEBUG Closing connection to the database "); $userMessages = array(); $errors = array( 'RFQReferenceNumberMismatchEx' => "Document Header Reference Number Value Mismatch", 'LineItemDescriptionMismatchEx' => "Line Item Description Mismatch", 'ActualLineItemCountMismatchEx' => "Actual Line Item Count Mismatch", 'LineItemCountMismatchEx' => "Document Header Line Item Count Attribute Value Mismatch", 'NoMatchingRFQWithRefenceFoundEx' => "There is no RFQ with a Reference No.: <refnumber> found within the last <no.ofdays>days that was sent by Buyer <buyertnid> to Match Supplier <matchsuppliertnid> that was forwarded by Match Buyer <matchbuyertnid> to Supplier <suppliertnid>", 'MatchFieldListNotFoundEx' => "The list of fields that will be used for matching is not set in the database", 'Unknown' => 'Other errors' ); foreach ($lines as $line) { if (!preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}:\d{3} ERROR \[(\w+)\] (.*)$/', $line, $matches)) { continue; } $errorCode = $matches[1]; $errorDetails = $matches[2]; if (!array_key_exists($errorCode, $errors)) { $errorCode = 'Unknown'; } if (array_key_exists($errorCode, $userMessages)) { $userMessages[$errorCode]['details'][] = $errorDetails; } else { $userMessages[$errorCode] = array( 'error' => $errors[$errorCode], 'details' => array( $errorDetails ) ); } } var_dump($userMessages);

preferences:
50.75 ms | 402 KiB | 5 Q