3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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; $tmp_word=($encoding_n!=='ASCII')?mb_convert_encoding($word,$encoding_n, 'ASCII'):$word; $tmp_w=($encoding_s!=='ASCII')?mb_convert_encoding($w,$encoding_s, 'ASCII'):$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.40.0120.00319.24
8.3.30.0040.01119.17
8.3.20.0030.00519.79
8.3.10.0040.00424.20
8.3.00.0080.00021.26
8.2.170.0080.00822.96
8.2.160.0180.00022.58
8.2.150.0050.00524.18
8.2.140.0100.00724.66
8.2.130.0080.00026.16
8.2.120.0080.00818.25
8.2.110.0030.00721.44
8.2.100.0150.00418.09
8.2.90.0100.00018.25
8.2.80.0110.00418.00
8.2.70.0030.00518.39
8.2.60.0060.00318.66
8.2.50.0170.00318.25
8.2.40.0070.00720.01
8.2.30.0000.00819.91
8.2.20.0030.00518.65
8.2.10.0000.00818.79
8.2.00.0030.00618.31
8.1.270.0030.00522.69
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0030.00618.52
8.1.230.0060.00618.52
8.1.220.0000.00918.27
8.1.210.0000.00918.77
8.1.200.0050.00917.85
8.1.190.0070.00717.85
8.1.180.0070.00718.16
8.1.170.0030.00619.16
8.1.160.0000.00819.51
8.1.150.0050.00319.50
8.1.140.0050.00322.61
8.1.130.0080.00320.85
8.1.120.0080.00018.09
8.1.110.0030.00518.07
8.1.100.0000.00818.05
8.1.90.0050.00317.99
8.1.80.0060.00318.02
8.1.70.0030.00517.99
8.1.60.0000.00918.11
8.1.50.0030.00618.14
8.1.40.0040.00418.15
8.1.30.0040.00418.24
8.1.20.0030.00618.28
8.1.10.0040.00418.21
8.1.00.0030.00518.21
8.0.300.0050.00518.77
8.0.290.0140.00317.38
8.0.280.0000.00819.09
8.0.270.0040.00417.86
8.0.260.0000.00719.13
8.0.250.0040.00417.63
8.0.240.0000.00817.65
8.0.230.0060.00617.40
8.0.220.0060.00317.41
8.0.210.0040.00417.46
8.0.200.0040.00417.55
8.0.190.0030.00617.43
8.0.180.0030.00517.58
8.0.170.0030.00617.60
8.0.160.0050.00317.63
8.0.150.0000.01117.45
8.0.140.0060.00317.48
8.0.130.0050.00214.09
8.0.120.0040.00417.38
8.0.110.0000.00817.59
8.0.100.0040.00417.61
8.0.90.0080.00017.51
8.0.80.0120.00917.64
8.0.70.0030.00517.38
8.0.60.0000.00817.48
8.0.50.0000.00817.30
8.0.30.0110.01617.59
8.0.20.0090.01217.74
8.0.10.0000.00817.55
8.0.00.0150.00717.59
7.4.330.0030.00315.55
7.4.320.0030.00317.25
7.4.300.0080.00017.19
7.4.290.0000.00716.96
7.4.280.0080.00017.20
7.4.270.0040.00817.03
7.4.260.0040.00417.19
7.4.250.0030.00617.20
7.4.240.0000.00817.26
7.4.230.0050.00217.21
7.4.220.0060.00317.42
7.4.210.0140.00617.32
7.4.200.0000.00717.29
7.4.160.0070.01317.16
7.4.140.0110.01017.86
7.4.130.0100.01117.23
7.4.120.0110.01017.11
7.4.110.0120.01517.21
7.4.100.0030.02117.01
7.4.90.0030.01617.18
7.4.80.0100.01019.39
7.4.70.0110.00717.14
7.4.60.0110.00717.04
7.4.50.0100.00517.20
7.4.40.0140.00717.02
7.4.10.0000.02015.16
7.4.00.0060.00715.21
7.3.330.0030.00314.01
7.3.320.0030.00314.01
7.3.310.0030.00616.91
7.3.300.0070.00016.77
7.3.290.0050.00316.83
7.3.280.0060.01316.87
7.3.260.0120.00816.91
7.3.240.0130.00616.96
7.3.230.0060.01216.95
7.3.210.0130.01317.04
7.3.200.0030.01517.10
7.3.190.0090.01316.97
7.3.180.0080.01117.11
7.3.170.0060.01816.94
7.3.160.0030.01517.11
7.3.130.0110.00714.75
7.3.120.0100.01014.78
7.3.110.0110.00714.79
7.3.100.0060.00914.88
7.3.90.0000.01715.10
7.3.80.0090.00314.91
7.3.70.0000.01315.16
7.3.60.0090.00615.11
7.3.50.0030.01214.95
7.3.40.0100.00614.78
7.3.30.0090.00914.89
7.3.20.0030.01016.61
7.3.10.0080.00816.79
7.3.00.0090.00316.60
7.2.330.0150.00617.30
7.2.320.0150.00917.07
7.2.310.0120.00917.23
7.2.300.0090.00917.22
7.2.290.0120.00617.39
7.2.260.0040.01815.27
7.2.250.0000.02014.92
7.2.240.0070.01115.31
7.2.230.0000.01215.23
7.2.220.0110.00414.97
7.2.210.0090.00615.11
7.2.200.0000.01515.25
7.2.190.0070.01015.25
7.2.180.0060.00615.01
7.2.170.0040.01115.24
7.2.160.0100.00715.30
7.2.150.0030.01016.83
7.2.140.0030.01317.08
7.2.130.0080.00617.12
7.2.120.0070.01017.08
7.2.110.0130.01016.43
7.2.100.0150.01016.24
7.2.90.0110.00816.34
7.2.80.0110.01016.43
7.2.70.0180.00816.49
7.2.60.0110.00816.37
7.2.50.0140.00516.40
7.2.40.0120.00816.45
7.2.30.0130.00816.44
7.2.20.0110.00816.30
7.2.10.0160.00416.40
7.2.00.0110.01016.45
7.1.330.0000.01415.96
7.1.320.0030.01315.99
7.1.310.0030.00915.99
7.1.300.0080.00615.95
7.1.290.0070.00715.82
7.1.280.0060.01315.94
7.1.270.0030.00915.80
7.1.260.0090.00616.04
7.1.250.0070.00615.83
7.1.240.0090.00315.85
7.1.230.0160.00814.86
7.1.220.0140.00715.07
7.1.210.0130.00715.02
7.1.200.0180.00514.93
7.1.190.0140.01214.81
7.1.180.0170.00315.05
7.1.170.0150.00715.00
7.1.160.0120.01014.77
7.1.150.0150.00714.93
7.1.140.0180.00614.82
7.1.130.0130.00914.86
7.1.120.0100.00814.80
7.1.110.0080.01015.06
7.1.100.0130.01414.80
7.1.90.0190.01015.01
7.1.80.0120.00514.90
7.1.70.0160.00714.90
7.1.60.0270.00623.72
7.1.50.0200.01123.78
7.1.40.0210.00823.91
7.1.30.0240.00923.82
7.1.20.0280.01123.48
7.1.10.0190.00314.83
7.1.00.0160.00814.83
7.0.330.0040.00715.63
7.0.320.0100.00715.60
7.0.310.0570.01014.61
7.0.300.0170.01014.72
7.0.290.0140.00814.70
7.0.280.0110.01314.42
7.0.270.0130.00814.53
7.0.260.0140.01214.60
7.0.250.0130.01114.65
7.0.240.0170.00514.57
7.0.230.0140.00914.52
7.0.220.0300.01114.90
7.0.210.0150.00314.69
7.0.200.0200.00814.55
7.0.190.0150.00614.53
7.0.180.0170.00814.52
7.0.170.0160.00914.62
7.0.160.0150.00614.72
7.0.150.0160.00514.71
7.0.140.0140.00714.70
7.0.130.0130.01314.53
7.0.120.0210.00514.64
7.0.110.0150.01014.59
7.0.100.0140.00714.54
7.0.90.0110.01414.44
7.0.80.0140.01014.54
7.0.70.0200.00814.62
7.0.60.0150.01114.48
7.0.50.0200.00714.77
7.0.40.0170.01013.56
7.0.30.0230.00613.70
7.0.20.0130.00813.52
7.0.10.0250.00413.67
7.0.00.0220.00613.41
5.6.400.0090.00614.22
5.6.390.0030.01014.46
5.6.380.0050.01014.67
5.6.370.0100.00914.79
5.6.360.0110.00514.57
5.6.350.0090.00814.85
5.6.340.0130.00614.54
5.6.330.0120.00514.63
5.6.320.0120.00614.79
5.6.310.0080.00914.71
5.6.300.0070.01214.78
5.6.290.0110.00714.51
5.6.280.0110.00514.63
5.6.270.0110.01114.84
5.6.260.0110.00714.69
5.6.250.0140.00314.70
5.6.240.0160.00514.55
5.6.230.0080.01114.40
5.6.220.0080.00814.68
5.6.210.0100.01014.55
5.6.200.0110.00814.53
5.6.190.0030.01314.80
5.6.180.0100.00614.52
5.6.170.0100.00714.47
5.6.160.0090.00914.42
5.6.150.0080.01014.42
5.6.140.0070.01214.62
5.6.130.0080.00814.64
5.6.120.0090.01114.45
5.6.110.0080.01014.62
5.6.100.0090.01014.58
5.6.90.0080.00814.85
5.6.80.0040.01614.45
5.6.70.0040.01514.46
5.6.60.0090.00814.36
5.6.50.0040.01414.46
5.6.40.0090.01014.20
5.6.30.0080.01314.29
5.6.20.0100.00814.70
5.6.10.0070.01314.59
5.6.00.0070.01414.41
5.5.380.0090.00911.34
5.5.370.0180.00311.46
5.5.360.0120.00311.51
5.5.350.0150.00411.29
5.5.340.0070.01011.49
5.5.330.0130.00611.36
5.5.320.0130.00511.47
5.5.310.0130.00311.30
5.5.300.0150.00511.51
5.5.290.0080.00811.58
5.5.280.0080.01111.39
5.5.270.0000.01511.31
5.5.260.0120.00511.31
5.5.250.0110.00811.32
5.5.240.0060.01211.29
5.5.230.0100.01011.29
5.5.220.0130.00311.46
5.5.210.0050.01011.29
5.5.200.0090.00911.29
5.5.190.0070.01311.29
5.5.180.0080.00811.37
5.5.170.0120.00914.14
5.5.160.0100.00711.29
5.5.150.0100.00611.46
5.5.140.0050.00911.29
5.5.130.0080.00811.45
5.5.120.0100.01011.47
5.5.110.0160.00511.40
5.5.100.0070.00711.29
5.5.90.0080.00811.29
5.5.80.0070.00711.29
5.5.70.0000.01711.50
5.5.60.0080.00811.29
5.5.50.0140.00311.31
5.5.40.0080.00411.36
5.5.30.0100.00711.34
5.5.20.0090.00811.29
5.5.10.0090.00511.29
5.5.00.0130.00311.37
5.4.450.0080.00811.55
5.4.440.0140.00411.50
5.4.430.0110.00711.29
5.4.420.0080.00811.29
5.4.410.0150.00411.29
5.4.400.0100.00611.32
5.4.390.0090.00911.29
5.4.380.0120.00311.29
5.4.370.0040.01211.41
5.4.360.0050.01311.29
5.4.350.0100.00511.29
5.4.340.0170.00011.29
5.4.330.0170.00311.48
5.4.320.0090.00611.33
5.4.310.0140.00511.29
5.4.300.0070.00711.34
5.4.290.0040.01211.29
5.4.280.0130.00411.29
5.4.270.0080.00811.29
5.4.260.0090.00611.29
5.4.250.0150.00011.29
5.4.240.0080.00511.41
5.4.230.0090.00911.29
5.4.220.0120.00411.29
5.4.210.0110.00311.29
5.4.200.0080.00811.29
5.4.190.0110.00811.29
5.4.180.0100.00711.29
5.4.170.0040.01311.29
5.4.160.0070.01111.29
5.4.150.0110.00611.33
5.4.140.0140.00311.30
5.4.130.0000.01411.29
5.4.120.0000.01311.29
5.4.110.0110.00511.29
5.4.100.0060.01211.29
5.4.90.0180.00011.29
5.4.80.0070.01011.29
5.4.70.0120.00511.29
5.4.60.0130.00411.29
5.4.50.0000.01711.29
5.4.40.0070.01111.29
5.4.30.0120.00611.29
5.4.20.0070.01011.29
5.4.10.0000.01611.35
5.4.00.0100.00511.29
5.3.290.0080.00811.29
5.3.280.0070.01011.29
5.3.270.0050.00811.29
5.3.260.0120.00411.29
5.3.250.0100.00611.29
5.3.240.0100.00711.29
5.3.230.0040.01111.29
5.3.220.0100.00311.29
5.3.210.0140.00411.29
5.3.200.0110.00411.29
5.3.190.0070.00511.29
5.3.180.0070.00811.29
5.3.170.0140.00311.29
5.3.160.0050.01111.29
5.3.150.0060.01211.29
5.3.140.0070.00711.29
5.3.130.0040.01111.29
5.3.120.0110.00311.29
5.3.110.0070.00711.29
5.3.100.0130.00011.29
5.3.90.0050.01111.29
5.3.80.0130.00011.29
5.3.70.0070.00711.29
5.3.60.0040.01111.29
5.3.50.0080.00811.29
5.3.40.0130.00311.29
5.3.30.0040.01211.29
5.3.20.0090.00411.29
5.3.10.0090.00611.29
5.3.00.0060.01011.29
5.2.170.0030.01011.29
5.2.160.0080.00611.29
5.2.150.0110.00411.29
5.2.140.0070.00511.29
5.2.130.0060.00811.29
5.2.120.0100.00511.29
5.2.110.0080.00811.29
5.2.100.0000.01311.29
5.2.90.0050.00511.29
5.2.80.0150.00011.29
5.2.70.0040.00811.29
5.2.60.0090.00611.29
5.2.50.0090.00311.29
5.2.40.0090.00411.29
5.2.30.0080.00411.29
5.2.20.0080.00511.29
5.2.10.0110.00411.29
5.2.00.0080.00411.29
5.1.60.0110.00011.29
5.1.50.0050.00511.29
5.1.40.0060.00611.29
5.1.30.0060.00811.29
5.1.20.0110.00311.29
5.1.10.0110.00011.29
5.1.00.0050.00511.29
5.0.50.0000.01111.29
5.0.40.0060.00311.29
5.0.30.0060.00611.29
5.0.20.0060.00611.29
5.0.10.0000.00911.29
5.0.00.0030.00711.29
4.4.90.0060.00311.29
4.4.80.0080.00311.29
4.4.70.0100.00011.29
4.4.60.0000.00811.29
4.4.50.0030.00611.29
4.4.40.0100.00011.29
4.4.30.0080.00011.29
4.4.20.0040.00411.29
4.4.10.0070.00211.29
4.4.00.0050.00511.29
4.3.110.0040.00411.29
4.3.100.0060.00411.29
4.3.90.0050.00511.29
4.3.80.0000.01011.29
4.3.70.0030.00311.29
4.3.60.0000.01011.29
4.3.50.0060.00311.29
4.3.40.0050.00511.29
4.3.30.0000.00611.29
4.3.20.0060.00011.29
4.3.10.0070.00011.29
4.3.00.0000.00511.29

preferences:
78.63 ms | 400 KiB | 5 Q