3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stripNonValidCharaters ($message) { $message = mb_convert_encoding($message, 'UTF-16', 'UTF-8'); $count = 0; //mostly taken from https://dynmark.uservoice.com/knowledgebase/articles/83496-gsm-alphabet-character-set $search = [ '`', '‘', '’', //single quotes '“', '”', //double quotes '~', '¬', '|' //misc ]; $replace = [ '\'', '\'', '\'', //single quotes '"', '"', //double quotes '-', '-', 'I' //misc ]; $message = str_replace($search, $replace, $message, $count); $validGSMKeycodes = [ 0x0040, 0x0394, 0x0020, 0x0030, 0x00a1, 0x0050, 0x00bf, 0x0070, 0x00A3, 0x005f, 0x0021, 0x0031, 0x0041, 0x0051, 0x0061, 0x0071, 0x0024, 0x03a6, 0x0022, 0x0032, 0x0042, 0x0052, 0x0062, 0x0072, 0x00a5, 0x0393, 0x0023, 0x0033, 0x0043, 0x0053, 0x0063, 0x0073, 0x00e8, 0x039b, 0x00a4, 0x0034, 0x0035, 0x0044, 0x0054, 0x0064, 0x0074, 0x00e9, 0x03a9, 0x0025, 0x0045, 0x0045, 0x0055, 0x0065, 0x0075, 0x00f9, 0x03a0, 0x0026, 0x0036, 0x0046, 0x0056, 0x0066, 0x0076, 0x00ec, 0x03a8, 0x0027, 0x0037, 0x0047, 0x0057, 0x0067, 0x0077, 0x00f2, 0x03a3, 0x0028, 0x0038, 0x0048, 0x0058, 0x0068, 0x0078, 0x00c7, 0x0398, 0x0029, 0x0039, 0x0049, 0x0059, 0x0069, 0x0079, 0x000a, 0x039e, 0x002a, 0x003a, 0x004a, 0x005a, 0x006a, 0x007a, 0x00d8, 0x001b, 0x002b, 0x003b, 0x004b, 0x00c4, 0x006b, 0x00e4, 0x00f8, 0x00c6, 0x002c, 0x003c, 0x004c, 0x00d6, 0x006c, 0x00f6, 0x000d, 0x00e6, 0x002d, 0x003d, 0x004d, 0x00d1, 0x006d, 0x00f1, 0x00c5, 0x00df, 0x002e, 0x003e, 0x004e, 0x00dc, 0x006e, 0x00fc, 0x00e5, 0x00c9, 0x002f, 0x003f, 0x004f, 0x00a7, 0x006f, 0x00e0, 0x03d5, 0x00E8, 0x00E9, 0x00F9, 0x00EC, 0x00F2, 0x00E7, 0x00D8, 0x00A5 ]; for($i = 0; $i < strlen($message); $i++) { echo mb_substr($message, $i, 1) . ' - '. hexdec(bin2hex(mb_substr($message, $i, 1)). "\n"; if(!in_array(hexdec(bin2hex(mb_substr($message, $i, 1))), $validGSMKeycodes, true)) { $message[$i] = ''; $count++; } } $message = mb_convert_encoding($message, 'UTF-8', 'UTF-16'); $message = trim($message); return ['message' => $message, 'replacements' => $count]; } $message= "@£\$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;>=<?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüàExtended: €[\]^{|}~"; var_dump(stripNonValidCharaters($message));

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)
5.4.340.0060.03512.05
5.4.320.0030.03912.54
5.4.310.0060.03712.54
5.4.300.0060.03712.54
5.4.290.0060.03812.54
5.4.280.0090.03212.43
5.4.270.0050.03712.43
5.4.260.0080.03612.43
5.4.250.0050.03812.43
5.4.240.0030.03812.43
5.4.230.0050.03812.42
5.4.220.0060.03512.42
5.4.210.0060.03612.42
5.4.200.0030.04412.42
5.4.190.0050.04012.42
5.4.180.0080.03312.42
5.4.170.0050.03712.43
5.4.160.0090.03212.42
5.4.150.0030.03812.41
5.4.140.0050.03812.11
5.4.130.0070.03612.09
5.4.120.0040.03912.05
5.4.110.0070.03712.05
5.4.100.0050.03712.05
5.4.90.0050.03712.05
5.4.80.0050.03812.05
5.4.70.0060.03412.05
5.4.60.0060.03412.04
5.4.50.0080.03312.04
5.4.40.0030.03712.04
5.4.30.0060.03612.03
5.4.20.0040.03912.03
5.4.10.0080.04912.03
5.4.00.0060.04411.52
5.3.290.0050.04212.80
5.3.280.0060.04112.71
5.3.270.0070.03912.72
5.3.260.0080.03612.72
5.3.250.0040.04212.72
5.3.240.0060.04012.72
5.3.230.0040.03912.71
5.3.220.0030.03912.68
5.3.210.0060.03912.68
5.3.200.0050.03712.68
5.3.190.0070.03612.68
5.3.180.0080.03412.68
5.3.170.0070.03612.67
5.3.160.0080.03912.68
5.3.150.0030.04012.67
5.3.140.0020.04012.66
5.3.130.0070.03712.66
5.3.120.0050.04612.66
5.3.110.0070.03712.65
5.3.100.0050.03812.13
5.3.90.0070.03812.11
5.3.80.0050.03612.09
5.3.70.0040.03812.09
5.3.60.0110.04012.08
5.3.50.0060.03612.02
5.3.40.0040.03812.02
5.3.30.0030.03711.98
5.3.20.0030.03811.77
5.3.10.0050.03611.73
5.3.00.0060.03511.72
5.2.170.0090.0269.22
5.2.160.0060.0289.22
5.2.150.0070.0289.22
5.2.140.0030.0319.21
5.2.130.0040.0299.17
5.2.120.0030.0299.18
5.2.110.0020.0319.18
5.2.100.0030.0299.18
5.2.90.0040.0289.18
5.2.80.0040.0309.17
5.2.70.0050.0299.18
5.2.60.0050.0299.13
5.2.50.0060.0289.10
5.2.40.0040.0299.07
5.2.30.0070.0279.05
5.2.20.0040.0299.05
5.2.10.0050.0278.95
5.2.00.0050.0348.80
5.1.60.0020.0268.09
5.1.50.0050.0258.09
5.1.40.0010.0278.07
5.1.30.0040.0268.43
5.1.20.0040.0268.44
5.1.10.0030.0268.17
5.1.00.0010.0288.17
5.0.50.0020.0236.64
5.0.40.0020.0206.51
5.0.30.0030.0316.31
5.0.20.0020.0216.28
5.0.10.0020.0206.26
5.0.00.0030.0306.26
4.4.90.0020.0164.78
4.4.80.0040.0144.75
4.4.70.0020.0164.75
4.4.60.0010.0174.76
4.4.50.0050.0124.77
4.4.40.0050.0224.70
4.4.30.0030.0154.76
4.4.20.0020.0164.84
4.4.10.0020.0164.85
4.4.00.0010.0264.76
4.3.110.0010.0184.67
4.3.100.0030.0154.66
4.3.90.0020.0164.63
4.3.80.0030.0244.58
4.3.70.0030.0144.63
4.3.60.0030.0144.63
4.3.50.0020.0174.63
4.3.40.0030.0244.54
4.3.30.0020.0163.30
4.3.20.0020.0183.28
4.3.10.0040.0143.25
4.3.00.0170.0238.12

preferences:
141.27 ms | 1394 KiB | 7 Q