3v4l.org

run code in 300+ PHP versions simultaneously
<?php $thisbatch = 1336; $description = 'Betalingskenmerk: 0815-69-AA-700' . "\n" . 'Transactiereferentie:'; $id = 1337; $refer = isolatenew($description); if($refer['result']=='success'){ // Reconciliate by new reference die('SUCCESS' . __LINE__); } elseif ($refer['result']=='fail'){ die('FAIL' . __LINE__); } else { // isolatenew returned partial success $suggestionFound = identify($refer, $id); if ($suggestionFound) { echo "UPDATE bank.transactions SET matched='$thisbatch',matchresult='104 Suggestie mail gestuurd naar operations' WHERE id='$id'\n"; } else { echo "UPDATE bank.transactions SET matched='$thisbatch',matchresult='101 Geen betaalkenmerk in omschrijving' WHERE id='$id'\n"; } } function isolatenew($input){ preg_match('#\d{3,5}[-_./ ]{0,2}\d{1,3}[-_./ ]{0,2}[a-zA-Z]{1,3}[-_./ ]{0,2}\d{3,5}#', $input, $result); if (!$result) { // Try hard, go pro! preg_match('#\d{5,7}[a-zA-Z]{1,3}\d{3,5}#', preg_replace('/[^a-zA-Z0-9]/', '', $input), $result); } if (empty($result)) { return array('result' => 'fail'); } else { //sql voor ophalen transacties van afgelopen week // eerst vervangen we eventuele dubbele streepjes met een enkel streepje $string = str_replace('--', '-', $result[0]); $string = str_replace(array(' ', '.','_','/'), '-', $string); if(strlen($string)==15&&substr_count($string, '-')==3){ $parts = explode('-', $string); if(strlen($parts[0])==4&&strlen($parts[1])==2&&strlen($parts[2])==2&&strlen($parts[3])==4){ return array('result' => 'success', 'return' => array($string)); } } $string = str_replace('-', '', $string); preg_match('/[A-Za-z]{1,3}/', $string, $lettersMatch); if (count($lettersMatch) >= 1) { $letters = $lettersMatch[0]; } else { // "Should never really happen" trigger_error('Bankwire matching: this should never really happen!', E_USER_WARNING); } if(strlen($string)==12&&strlen($letters)==2){ $str = substr($string, 0, 4) . '-' . substr($string, 4,2). '-' . substr($string, 6,2). '-' . substr($string, 8,4); return array('result' => 'success', 'return' => array($str)); } else { //doe exploden op de letters kijken welke onderdelen te salvagen zijn $str = explode($letters, $string); $lettersarray = array(); if(strlen($letters)==1){ $lettersarray = array( $letters.'A', $letters.'B', $letters.'C', $letters.'D', $letters.'E', $letters.'F', $letters.'G', $letters.'H', $letters.'J', $letters.'K', $letters.'L', $letters.'M', $letters.'N', $letters.'P', $letters.'Q', $letters.'R', $letters.'S', $letters.'T', $letters.'U', $letters.'V', $letters.'W', $letters.'X', $letters.'Y', $letters.'Z', 'A'.$letters, 'B'.$letters, 'C'.$letters, 'D'.$letters, 'E'.$letters, 'F'.$letters, 'G'.$letters, 'H'.$letters, 'J'.$letters, 'K'.$letters, 'L'.$letters, 'M'.$letters, 'N'.$letters, 'P'.$letters, 'Q'.$letters, 'R'.$letters, 'S'.$letters, 'T'.$letters, 'U'.$letters, 'V'.$letters, 'W'.$letters, 'X'.$letters, 'Y'.$letters, 'Z'.$letters ); } else if (strlen($letters) == 2) { $lettersarray[] = $letters; } else if(strlen($letters)==3){ $lettersarray[substr($letters, 0, 2)] = substr($letters, 0, 2); $lettersarray[substr($letters, 1, 2)] = substr($letters, 1, 2); $lettersarray[substr($letters, 0, 1).substr($letters, 2, 1)] = substr($letters, 0, 1).substr($letters, 2, 1); } $return[] = substr($string, 0, 4) . '-' . substr($string, 4,2). '-' . substr($string, 6,2). '-' . substr($string, 8,4); foreach($lettersarray as $letter){ $return[] = substr($str[0], 0, 4).'-'.substr($str[0], -2).'-'.$letter.'-'.substr($str[1], 0, 4); $return[] = substr($str[0], 0, 4).'-'.substr($str[0], -2).'-'.$letter.'-'.substr($str[1], 1, 4); } if(strlen($str[0])==6&&strlen($str[1])==4){ return array('result' => 'p_success_3', 'return' => $return, 'original' => $input); } if(strlen($str[0])==6&&strlen($str[1])!=4){ return array('result' => 'p_success_4', 'return' => $return, 'original' => $input); } if(strlen($str[0])!=6&&strlen($str[1])==4){ return array('result' => 'p_success_1_2', 'return' => $return, 'original' => $input); } } } } function findFuzzyMatches ($needle, $haystack, $tolerance = 1) { /* Returns (fuzzy) matches between $needle and elements of $haystack. The selected matches are those having Levenshtein distance up to $tolerance. Give $tolerance = -1 to get all matches. Return type is an associative array: the keys are the Levenshtein distance (integer), the values are sub-arrays containing the elements of $haystack having that distance. E.g.: $needle = 'abc'; $haystack = array('abc', 'abd', 'abe', 'xyz'); returns: array( 0 => array('abc'), 1 => array('abd', 'abe'), 3 => array('xyz') ) */ $matches = array(); // key: distance, value: sub-array with candidates having that distance foreach ($haystack as $candidateKey => $candidate) { // NOTE: Slowness? Use levenshtein, which is the faster function of the two. //$distance = levenshtein($needle, $candidate); // Downside: character swaps cost 2 instead of 1. $distance = DamerauLevenshtein($needle, $candidate); if ($distance <= $tolerance || $tolerance == -1) { if (!array_key_exists($distance, $matches)) { $matches[$distance] = array(); } $matches[$distance][$candidateKey] = $candidate; } } return $matches; } function DamerauLevenshtein($str1, $str2) { $d = Array(); $lenStr1 = strlen($str1); $lenStr2 = strlen($str2); if ($lenStr1 == 0) { return $lenStr2; } if ($lenStr2 == 0) { return $lenStr1; } for ($i=0; $i <= $lenStr1; $i++) { $d[$i] = Array(); $d[$i][0] = $i; } for ($j=0; $j <= $lenStr2; $j++) { $d[0][$j] = $j; } for ($i=1; $i <= $lenStr1; $i++) { for ($j=1; $j <= $lenStr2; $j++) { $cost = substr($str1, $i - 1, 1) == substr($str2, $j - 1, 1) ? 0 : 1; $d[$i][$j] = min( $d[$i - 1][$j] + 1, // deletion $d[$i][$j - 1] + 1, // insertion $d[$i - 1][$j - 1] + $cost // substitution ); if ( $i > 1 && $j > 1 && substr($str1, $i - 1, 1) == substr($str2, $j - 2, 1) && substr($str1, $i - 2, 1) == substr($str2, $j - 1, 1) ) { $d[$i][$j] = min( $d[$i][$j], $d[$i - 2][$j - 2] + $cost // transposition ); } } } return $d[$lenStr1][$lenStr2]; } function identify($refer, $bankTransactionID){ /* Returns whether a mail suggestion was sent to operations. If not, no sensible suggestion was found and the transaction should be rolled back. */ $suggestionFound = false; $weekstransactions = array(1338 => '0815-69-AA-7007'); foreach($refer['return'] as $reference){ $match = findFuzzyMatches($reference, $weekstransactions, 2); // $match contains all matches grouped by distance. Every match inside such a distance-array is keyed by its original saleID. $matches[$reference] = $match; } $mailbody = 'Input: "'.$refer['original'].'"'."\r\n"; $mailbody .= 'bank.transaction.id: '.$bankTransactionID."\r\n\r\n"; foreach($refer['return'] as $reference){ $mailbody .= 'mogelijke reference waarop we hebben gezocht: ' . $reference."\r\n"; if (empty($matches[$reference])) { $mailbody .= 'Niet gevonden!' . "\r\n\r\n"; } else { foreach($matches[$reference] as $key => $possibles){ $mailbody .= 'waarschijnlijkheid: ' . $key."\r\n"; foreach($possibles as $saleID => $possible){ $mailbody .= 'saleID: ' . $saleID."\r\n"; $mailbody .= 'reference: ' . $possible."\r\n"; $suggestionFound = true; } $mailbody .= "\r\n"; } $mailbody .= "\r\n\r\n"; } } if ($suggestionFound) { //mail('steven@targetmedia.nl', 'Bankwire', $mailbody); print 'MAILING' . "\n\n" . $mailbody; } return $suggestionFound; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0070.01117.00
8.3.50.0120.00721.96
8.3.40.0190.00319.04
8.3.30.0000.01519.39
8.3.20.0060.00320.41
8.3.10.0050.00323.64
8.3.00.0060.00319.63
8.2.180.0090.00618.42
8.2.170.0090.00622.96
8.2.160.0120.00320.78
8.2.150.0000.00824.18
8.2.140.0120.00624.66
8.2.130.0040.00426.16
8.2.120.0040.00422.56
8.2.110.0060.00320.47
8.2.100.0060.00618.29
8.2.90.0030.00618.44
8.2.80.0040.00418.05
8.2.70.0090.00018.00
8.2.60.0080.00018.16
8.2.50.0000.00818.07
8.2.40.0050.00318.47
8.2.30.0000.00918.40
8.2.20.0080.00017.98
8.2.10.0000.00918.32
8.2.00.0000.01017.98
8.1.280.0030.01225.92
8.1.270.0100.01022.39
8.1.260.0030.00526.35
8.1.250.0050.00328.09
8.1.240.0040.00422.34
8.1.230.0080.00421.20
8.1.220.0040.00418.02
8.1.210.0030.00619.08
8.1.200.0060.00317.63
8.1.190.0050.00317.90
8.1.180.0030.00618.10
8.1.170.0030.00619.03
8.1.160.0000.00822.21
8.1.150.0030.00618.88
8.1.140.0040.00417.64
8.1.130.0000.00718.00
8.1.120.0080.00017.84
8.1.110.0030.00617.75
8.1.100.0000.00917.70
8.1.90.0000.00817.77
8.1.80.0060.00317.70
8.1.70.0000.00717.79
8.1.60.0100.00017.88
8.1.50.0050.00317.91
8.1.40.0060.00317.79
8.1.30.0000.00917.92
8.1.20.0040.00417.84
8.1.10.0080.00017.86
8.1.00.0060.00317.86
8.0.300.0030.00620.39
8.0.290.0030.00617.30
8.0.280.0030.00518.68
8.0.270.0040.00417.45
8.0.260.0040.00417.05
8.0.250.0040.00417.24
8.0.240.0030.00517.30
8.0.230.0070.00017.24
8.0.220.0000.00717.14
8.0.210.0000.00717.22
8.0.200.0050.00317.29
8.0.190.0000.00817.34
8.0.180.0040.00417.19
8.0.170.0040.00417.20
8.0.160.0040.00417.26
8.0.150.0000.00817.18
8.0.140.0000.01217.06
8.0.130.0000.00613.70
8.0.120.0050.00317.20
8.0.110.0030.00617.23
8.0.100.0040.00417.09
8.0.90.0040.00417.09
8.0.80.0040.01117.22
8.0.70.0000.00817.02
8.0.60.0040.00417.02
8.0.50.0050.00317.08
8.0.30.0070.01317.44
8.0.20.0130.00717.58
8.0.10.0030.00617.21
8.0.00.0130.00717.13
7.4.330.0030.00315.00
7.4.320.0030.00316.89
7.4.300.0040.00417.02
7.4.290.0040.00416.93
7.4.280.0000.00816.87
7.4.270.0040.00416.91
7.4.260.0080.00017.01
7.4.250.0060.00316.83
7.4.240.0000.00716.91
7.4.230.0000.00716.81
7.4.220.0130.00616.83
7.4.210.0110.00717.01
7.4.200.0000.00817.07
7.4.190.0040.00417.11
7.4.160.0130.00916.95
7.4.150.0060.01217.40
7.4.140.0070.01117.86
7.4.130.0120.00616.93
7.4.120.0110.00816.90
7.4.110.0110.01416.75
7.4.100.0090.01217.00
7.4.90.0060.01216.98
7.4.80.0150.00919.39
7.4.70.0160.00916.99
7.4.60.0060.01216.86
7.4.50.0000.00916.73
7.4.40.0180.00022.77
7.4.30.0110.00616.94
7.4.00.0120.00315.36
7.3.330.0000.00613.54
7.3.320.0000.00613.54
7.3.310.0080.00016.73
7.3.300.0000.00716.69
7.3.290.0060.01616.70
7.3.280.0100.01116.71
7.3.270.0150.00317.40
7.3.260.0160.00916.94
7.3.250.0100.01016.66
7.3.240.0060.01716.71
7.3.230.0110.00716.67
7.3.210.0180.00016.79
7.3.200.0090.01319.39
7.3.190.0190.00316.71
7.3.180.0130.00316.70
7.3.170.0030.01416.83
7.3.160.0140.00316.93
7.3.120.0110.00015.34
7.3.110.0040.01215.04
7.3.100.0030.00915.33
7.3.90.0000.01515.14
7.3.80.0030.01214.86
7.3.70.0090.00914.94
7.3.60.0110.00315.00
7.3.50.0080.00614.98
7.3.40.0070.00715.19
7.3.30.0030.01015.13
7.3.20.0090.00616.71
7.3.10.0060.00916.82
7.3.00.0060.00616.80
7.2.330.0030.01617.14
7.2.320.0160.00316.83
7.2.310.0110.00917.05
7.2.300.0190.00316.94
7.2.290.0070.01016.83
7.2.240.0000.01915.53
7.2.230.0070.00715.35
7.2.220.0030.01315.32
7.2.210.0120.00615.40
7.2.200.0030.01315.29
7.2.190.0030.01215.32
7.2.180.0080.00415.33
7.2.170.0000.01515.40
7.2.160.0040.01415.33
7.2.150.0060.00917.21
7.2.140.0030.00817.13
7.2.130.0030.01117.10
7.2.120.0100.00317.18
7.2.110.0070.00716.79
7.2.100.0070.01017.13
7.2.90.0030.01016.94
7.2.80.0070.00716.88
7.2.70.0070.00717.02
7.2.60.0080.00717.17
7.2.50.0090.00617.10
7.2.40.0030.01017.07
7.2.30.0060.01017.00
7.2.20.0060.00617.19
7.2.10.0040.00817.15
7.2.00.0020.01018.39
7.1.330.0030.01016.09
7.1.320.0030.00915.74
7.1.310.0040.01215.85
7.1.300.0070.00315.98
7.1.290.0000.00916.04
7.1.280.0080.00415.90
7.1.270.0040.00415.79
7.1.260.0030.01016.03
7.1.250.0060.00615.84
7.1.100.0070.00718.07
7.1.70.0000.00917.49
7.1.60.0070.02019.33
7.1.50.0160.00317.20
7.1.00.0030.07722.32
7.0.200.0060.00616.92
7.0.140.0130.06722.08
7.0.100.0300.07020.20
7.0.90.0200.08020.14
7.0.80.0200.07720.18
7.0.70.0230.07020.16
7.0.60.0100.06320.08
7.0.50.0100.08320.55
7.0.40.0070.07719.96
7.0.30.0100.08720.05
7.0.20.0070.07319.98
7.0.10.0130.07720.00
7.0.00.0100.08020.12
5.6.280.0000.08021.11
5.6.250.0130.08020.85
5.6.240.0030.09320.75
5.6.230.0100.09320.67
5.6.220.0000.07720.56
5.6.210.0100.07720.55
5.6.200.0130.08021.17
5.6.190.0030.08021.25
5.6.180.0130.08021.13
5.6.170.0030.08721.17
5.6.160.0030.09321.12
5.6.150.0030.08021.12
5.6.140.0130.07021.07
5.6.130.0100.07321.05
5.6.120.0000.08321.09
5.6.110.0100.08321.13
5.6.100.0070.05321.09
5.6.90.0070.08021.11
5.6.80.0100.08020.41
5.6.70.0130.07320.49
5.6.60.0000.08720.52
5.6.50.0100.07720.56
5.6.40.0100.08020.54
5.6.30.0130.03720.57
5.6.20.0100.06720.53
5.6.10.0030.04720.56
5.6.00.0070.06720.46
5.5.380.0070.05020.49
5.5.370.0100.08020.46
5.5.360.0070.07720.46
5.5.350.0030.08320.52
5.5.340.0100.07320.84
5.5.330.0130.08320.71
5.5.320.0070.09021.00
5.5.310.0030.08720.84
5.5.300.0170.07320.96
5.5.290.0070.08720.91
5.5.280.0100.08720.90
5.5.270.0070.08020.95
5.5.260.0130.07720.82
5.5.250.0100.08320.62
5.5.240.0130.07320.30
5.5.230.0100.07720.23
5.5.220.0070.08320.29
5.5.210.0130.08020.37
5.5.200.0100.06320.32
5.5.190.0030.05020.26
5.5.180.0070.06320.31
5.5.160.0070.04720.29
5.5.150.0170.03320.34
5.5.140.0070.04320.22
5.5.130.0170.08020.33
5.5.120.0070.06020.25
5.5.110.0070.08020.32
5.5.100.0200.07020.15
5.5.90.0070.07320.14
5.5.80.0070.07720.01
5.5.70.0000.08020.04
5.5.60.0100.08020.23
5.5.50.0070.07720.21
5.5.40.0070.06020.14
5.5.30.0100.07020.21
5.5.20.0130.08020.22
5.5.10.0030.05720.18
5.5.00.0100.07320.14
5.4.450.0070.08319.47
5.4.440.0000.09319.23
5.4.430.0100.07719.39
5.4.420.0170.06019.39
5.4.410.0130.07319.17
5.4.400.0070.07719.14
5.4.390.0070.05718.91
5.4.380.0070.07319.04
5.4.370.0130.07319.16
5.4.360.0100.07719.13
5.4.350.0130.06719.20
5.4.340.0000.05019.23
5.4.320.0070.07719.16
5.4.310.0100.08018.91
5.4.300.0030.06719.10
5.4.290.0030.06019.09
5.4.280.0100.08019.23
5.4.270.0100.08019.05
5.4.260.0070.04319.24
5.4.250.0070.07019.13
5.4.240.0000.06318.86
5.4.230.0100.07719.13
5.4.220.0030.07319.19
5.4.210.0100.07019.02
5.4.200.0070.08019.05
5.4.190.0130.04719.22
5.4.180.0170.07018.86
5.4.170.0070.07318.86
5.4.160.0200.04718.86
5.4.150.0170.07019.13
5.4.140.0070.07316.34
5.4.130.0030.07716.41
5.4.120.0070.07316.40
5.4.110.0070.07016.45
5.4.100.0070.04016.34
5.4.90.0100.06316.49
5.4.80.0030.07016.51
5.4.70.0000.04016.48
5.4.60.0100.07016.42
5.4.50.0100.03716.47
5.4.40.0000.04016.41
5.4.30.0000.04316.50
5.4.20.0000.06016.30
5.4.10.0100.04716.54
5.4.00.0030.03715.88
5.3.290.0000.08314.86
5.3.280.0100.06714.79
5.3.270.0100.08014.71
5.3.260.0030.07314.82
5.3.250.0000.08714.84
5.3.240.0100.07714.74
5.3.230.0030.07314.84
5.3.220.0130.07714.75
5.3.210.0100.07714.80
5.3.200.0000.06014.70
5.3.190.0130.03714.66
5.3.180.0070.03714.75
5.3.170.0070.03714.78
5.3.160.0000.04314.67
5.3.150.0030.04314.72
5.3.140.0130.05014.74
5.3.130.0030.07714.60
5.3.120.0070.03314.66
5.3.110.0030.04014.65
5.3.100.0030.06714.23
5.3.90.0030.03714.10
5.3.80.0070.03014.07
5.3.70.0130.04714.26
5.3.60.0070.04314.05
5.3.50.0000.06314.06
5.3.40.0100.05313.98
5.3.30.0100.02713.92
5.3.20.0070.04013.88
5.3.10.0070.03013.79
5.3.00.0030.03313.90

preferences:
43.6 ms | 401 KiB | 5 Q