3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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.4.9, 5.0.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
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) { }