3v4l.org

run code in 300+ PHP versions simultaneously
<?php function to_ascii($text,$encoding="UTF-8") { if (is_string($text)) { // Includes combinations of characters that present as a single glyph $text = preg_replace_callback('/\X/u', __FUNCTION__, $text); } elseif (is_array($text) && count($text) == 1 && is_string($text[0])) { // IGNORE characters that can't be TRANSLITerated to ASCII $text = @iconv($encoding, "ASCII//IGNORE//TRANSLIT", $text[0]); // The documentation says that iconv() returns false on failure but it returns '' if ($text === '' || !is_string($text)) { $text = '?'; } elseif (preg_match('/\w/', $text)) { // If the text contains any letters... $text = preg_replace('/\W+/', '', $text); // ...then remove all non-letters } } else { // $text was not a string $text = ''; } return $text; } function find_similar3($needle,$str,$keep_needle_order=false){ if(!is_string($needle)||!is_string($str)) { return false; } $valid=array(); //get encodings and words from haystack and needle setlocale(LC_CTYPE, 'en_GB.UTF8'); $encoding_s=mb_detect_encoding($str); $encoding_n=mb_detect_encoding($needle); mb_regex_encoding ($encoding_n); $pneed=array_filter(mb_split('\W',$needle)); mb_regex_encoding ($encoding_s); $pstr=array_filter(mb_split('\W',$str)); foreach($pneed as $k=>$word)//loop trough needle's words { foreach($pstr as $key=>$w) { if($encoding_n!==$encoding_s) {//if $encodings are not the same make some transliteration $tmp_word=($encoding_n!=='ASCII')?to_ascii($word,$encoding_n):$word; $tmp_w=($encoding_s!=='ASCII')?to_ascii($w,$encoding_s):$w; }else { $tmp_word=$word; $tmp_w=$w; } $tmp[$tmp_w]=levenshtein($tmp_w,$tmp_word);//collect levenshtein distances $keys[$tmp_w]=array($key,$w); } $nominees=array_flip(array_keys($tmp,min($tmp)));//get the nominees $tmp=10000; foreach($nominees as $nominee=>$idx) {//test sound like to get more precision $idx=levenshtein(metaphone($nominee),metaphone($tmp_word)); if($idx<$tmp){ $answer=$nominee;//get the winner } unset($nominees[$nominee]); } if(!$keep_needle_order){ $valid[$keys[$answer][0]]=$keys[$answer][1];//get the right form of the winner } else{ $valid[$k]=$keys[$answer][1]; } $tmp=$nominees=array();//clean a little for the next iteration } if(!$keep_needle_order) { ksort($valid); } $valid=array_values($valid);//get only the values /*return the array of the closest value to the needle according to this algorithm of course*/ return $valid; } var_dump(find_similar3('i knew you love me','finally i know you loved me and all my pets')); var_dump(find_similar3('I you love','This is a demo text and I love you about this')); var_dump(find_similar3('a unik idia','I have a unique idea. Do you need?')); var_dump(find_similar3("Goebel, Weiss, Goethe, Goethe und Goetz",'Weiß, Goldmann, Göbel, Weiss, Göthe, Goethe und Götz')); var_dump(find_similar3('Ḽơᶉëᶆ ȋṕšᶙṁ ḍỡḽǭᵳ ʂǐť ӓṁệẗ, ĉṓɲṩḙċťᶒțûɾ ấɖḯƥĭṩčįɳġ ḝłįʈ', 'Ḽơᶉëᶆ ȋṕšᶙṁ ḍỡḽǭᵳ ʂǐť ӓṁệẗ, ĉṓɲṩḙċťᶒțûɾ ấɖḯƥĭṩčįɳġ ḝłįʈ, șếᶑ ᶁⱺ ẽḭŭŝḿꝋď ṫĕᶆᶈṓɍ ỉñḉīḑȋᵭṵńť ṷŧ ḹẩḇőꝛế éȶ đꝍꞎôꝛȇ ᵯáꞡᶇā ąⱡîɋṹẵ.'));

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.110.0070.01119.20
8.3.100.0160.00317.40
8.3.90.0060.00326.77
8.3.80.0100.00019.31
8.3.70.0150.01517.75
8.3.60.0210.01122.49
8.3.50.0090.01221.39
8.3.40.0190.01022.76
8.3.30.0200.00722.82
8.3.20.0140.00922.85
8.3.10.0160.00624.16
8.3.00.0160.00423.53
8.2.230.0100.01020.94
8.2.220.0160.00024.06
8.2.210.0040.01126.77
8.2.200.0030.00717.50
8.2.190.0100.01017.75
8.2.180.0080.01022.72
8.2.170.0200.00822.89
8.2.160.0210.00524.44
8.2.150.0160.00725.05
8.2.140.0190.00825.29
8.2.130.0180.00926.04
8.2.120.0210.00523.25
8.2.110.0190.00722.91
8.2.100.0230.00622.41
8.2.90.0150.00923.03
8.2.80.0200.00522.09
8.2.70.0190.00622.15
8.2.60.0160.01022.29
8.2.50.0180.00622.21
8.2.40.0180.00722.32
8.2.30.0170.00522.41
8.2.20.0130.00621.54
8.2.10.0100.00821.54
8.2.00.0140.00521.50
8.1.290.0070.00330.84
8.1.280.0350.00025.92
8.1.270.0180.00725.29
8.1.260.0150.00726.14
8.1.250.0180.00527.00
8.1.240.0170.00523.96
8.1.230.0150.00822.84
8.1.220.0140.00822.17
8.1.210.0160.00722.35
8.1.200.0190.00322.14
8.1.190.0190.00622.07
8.1.180.0290.00522.05
8.1.170.0230.00622.78
8.1.160.0130.00822.79
8.1.150.0100.00621.67
8.1.140.0090.00722.68
8.1.130.0090.00822.71
8.1.120.0100.00721.82
8.1.110.0120.00521.79
8.1.100.0110.00621.82
8.1.90.0090.00721.78
8.1.80.0100.00721.83
8.1.70.0100.00721.80
8.1.60.0110.00821.93
8.1.50.0120.00821.86
8.1.40.0100.01021.28
8.1.30.0140.00621.37
8.1.20.0130.00621.33
8.1.10.0130.00521.36
8.1.00.0130.00521.32
8.0.300.0190.00222.35
8.0.290.0180.00621.77
8.0.280.0130.01122.57
8.0.270.0120.00820.86
8.0.260.0080.00921.95
8.0.250.0120.00921.50
8.0.240.0120.00520.94
8.0.230.0170.00320.87
8.0.220.0140.00420.90
8.0.210.0100.00720.95
8.0.200.0090.01020.91
8.0.190.0150.00520.90
8.0.180.0140.00420.91
8.0.170.0160.00320.93
8.0.160.0120.00820.91
8.0.150.0130.00520.82
8.0.140.0160.00220.88
8.0.130.0140.00219.71
8.0.120.0110.00720.98
8.0.110.0110.00720.95
8.0.100.0150.00620.98
8.0.90.0130.00720.99
8.0.80.0140.00920.20
8.0.70.0110.00820.96
8.0.60.0110.00720.94
8.0.50.0150.00421.03
8.0.30.0120.01020.90
8.0.20.0140.01021.02
8.0.10.0120.00620.86
8.0.00.0120.01020.18
7.4.330.0120.00619.90
7.4.320.0150.00520.75
7.4.300.0070.01119.40
7.4.290.0180.00320.66
7.4.280.0190.00420.65
7.4.270.0130.00820.64
7.4.260.0150.00620.66
7.4.250.0130.00620.74
7.4.240.0130.00820.78
7.4.230.0160.00420.67
7.4.220.0140.00720.76
7.4.210.0110.01019.53
7.4.200.0120.00720.78
7.4.190.0180.00522.33
7.4.180.0200.00422.33
7.4.160.0110.01420.70
7.4.150.0190.00522.28
7.4.140.0180.00719.10
7.4.130.0190.00820.61
7.4.120.0130.01218.89
7.4.110.0150.01220.67
7.4.100.0160.01020.75
7.4.90.0100.01220.74
7.4.80.0130.01021.29
7.4.70.0120.01019.77
7.4.60.0180.00719.84
7.4.50.0100.01319.80
7.4.40.0170.00919.83
7.4.30.0160.01020.57
7.4.20.0150.01120.57
7.4.10.0170.00919.31
7.4.00.0160.00818.45
7.3.330.0140.00419.45
7.3.320.0150.00419.54
7.3.310.0120.00720.56
7.3.300.0130.00520.44
7.3.290.0120.00720.50
7.3.280.0140.00919.24
7.3.270.0260.00222.11
7.3.260.0140.00918.92
7.3.250.0230.00422.19
7.3.240.0110.01119.00
7.3.230.0160.00620.54
7.3.220.0190.00522.11
7.3.210.0160.00820.56
7.3.200.0130.01120.46
7.3.190.0130.01419.67
7.3.180.0180.00719.61
7.3.170.0160.01019.71
7.3.160.0170.00919.77
7.3.150.0170.01120.55
7.3.140.0190.00920.54
7.3.130.0210.00619.22
7.3.120.0180.00719.30
7.3.110.0180.00819.29
7.3.100.0130.01119.11
7.3.90.0170.00919.22
7.3.80.0190.01219.31
7.3.70.0180.00819.22
7.3.60.0150.01319.30
7.3.50.0140.01219.24
7.3.40.0140.01119.25
7.3.30.0180.00519.25
7.3.20.0180.00620.05
7.3.10.0140.01120.12
7.3.00.0140.01020.13
7.2.340.0190.00422.26
7.2.330.0140.01020.60
7.2.320.0150.01020.70
7.2.310.0140.00919.88
7.2.300.0160.00819.83
7.2.290.0140.00819.85
7.2.280.0170.01120.69
7.2.270.0200.00820.61
7.2.260.0150.01119.40
7.2.250.0140.01019.34
7.2.240.0160.01319.38
7.2.230.0150.01019.40
7.2.220.0160.01219.34
7.2.210.0170.01019.40
7.2.200.0180.00919.39
7.2.190.0150.01019.39
7.2.180.0140.01219.34
7.2.170.0170.00819.40
7.2.160.0170.00719.31
7.2.150.0170.00920.31
7.2.140.0120.01220.23
7.2.130.0190.00920.32
7.2.120.0160.01020.28
7.2.110.0130.01119.22
7.2.100.0130.01419.28
7.2.90.0260.01019.25
7.2.80.0180.01019.25
7.2.70.0220.00819.32
7.2.60.0160.01119.35
7.2.50.0170.01019.31
7.2.40.0350.00719.33
7.2.30.0320.01019.43
7.2.20.0160.00919.35
7.2.10.0170.00819.36
7.2.00.0150.01019.40
7.1.330.0130.01019.54
7.1.320.0160.00919.52
7.1.310.0160.00819.54
7.1.300.0150.01019.44
7.1.290.0140.01019.50
7.1.280.0160.00819.52
7.1.270.0150.00819.51
7.1.260.0170.00719.41
7.1.250.0190.01019.46
7.1.240.0150.01219.40
7.1.230.0240.00718.37
7.1.220.0140.01118.44
7.1.210.0130.01118.45
7.1.200.0090.01318.48
7.1.190.0300.00918.49
7.1.180.0230.01018.53
7.1.170.0160.00618.39
7.1.160.0210.00918.40
7.1.150.0150.00918.50
7.1.140.0190.01218.40
7.1.130.0170.00718.39
7.1.120.0240.01018.41
7.1.110.0190.00918.42
7.1.100.0210.01018.43
7.1.90.0310.00818.42
7.1.80.0270.00618.50
7.1.70.0230.01018.45
7.1.60.0190.01221.87
7.1.50.0210.01121.81
7.1.40.0180.00922.00
7.1.30.0310.00821.90
7.1.20.0380.00721.95
7.1.10.0390.01318.44
7.1.00.0320.01118.44
7.0.330.0150.00919.23
7.0.320.0150.00719.19
7.0.310.0140.00919.23
7.0.300.0250.00519.20
7.0.290.0140.00819.17
7.0.280.0140.00819.22
7.0.270.0140.00819.25
7.0.260.0120.01119.17
7.0.250.0160.00819.23
7.0.240.0150.00819.24
7.0.230.0160.00719.30
7.0.220.0130.01119.28
7.0.210.0140.00919.25
7.0.200.0140.01019.24
7.0.190.0160.00719.24
7.0.180.0130.01219.26
7.0.170.0120.01119.25
7.0.160.0160.01019.24
7.0.150.0150.00919.20
7.0.140.0130.00919.32
7.0.130.0130.00919.19
7.0.120.0120.01119.30
7.0.110.0130.01119.30
7.0.100.0130.00819.18
7.0.90.0160.00919.10
7.0.80.0130.01219.11
7.0.70.0250.00619.14
7.0.60.0190.00619.24
7.0.50.0150.00719.24
7.0.40.0120.00918.70
7.0.30.0180.00918.71
7.0.20.0150.00818.77
7.0.10.0170.00718.76
7.0.00.0160.00918.74
5.6.400.0180.00818.89
5.6.390.0150.00919.08
5.6.380.0130.00918.06
5.6.370.0100.01319.02
5.6.360.0100.01318.90
5.6.350.0150.01018.96
5.6.340.0160.00819.01
5.6.330.0150.00719.11
5.6.320.0110.01419.02
5.6.310.0110.01419.08
5.6.300.0140.00918.94
5.6.290.0120.01018.98
5.6.280.0150.01018.97
5.6.270.0120.01318.96
5.6.260.0150.01018.95
5.6.250.0160.01018.91
5.6.240.0130.01218.94
5.6.230.0170.00818.96
5.6.220.0140.01019.00
5.6.210.0140.01419.04
5.6.200.0140.01018.94
5.6.190.0140.01019.05
5.6.180.0160.00818.95
5.6.170.0180.00618.96
5.6.160.0090.01418.91
5.6.150.0120.01218.89
5.6.140.0140.00918.93
5.6.130.0120.01118.94
5.6.120.0170.00718.99
5.6.110.0130.01118.99
5.6.100.0150.00818.98
5.6.90.0120.01218.91
5.6.80.0110.01118.92
5.6.70.0120.01019.01
5.6.60.0140.01119.00
5.6.50.0120.01218.79
5.6.40.0130.01119.02
5.6.30.0180.00518.83
5.6.20.0160.00718.95
5.6.10.0150.01018.96
5.6.00.0160.00618.92

preferences:
29.31 ms | 403 KiB | 5 Q