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);
Output for 4.3.10 - 4.3.11, 4.4.0 - 4.4.9, 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.17 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(1) { ["ActualLineItemCountMismatchEx"]=> array(2) { ["error"]=> string(31) "Actual Line Item Count Mismatch" ["details"]=> array(2) { [0]=> string(37) "Doc Changed on Actual Line Item Count" [1]=> string(16) "7 not equal to 2" } } }
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/4DUQE on line 3 array(0) { }

preferences:
275.8 ms | 402 KiB | 380 Q