3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class Escaper { protected $encoding; public function __construct(string $encoding) { $this->encoding = $encoding; } public function js(string $input) : string { // json_encode can only accept UTF-8 encoded strings. if ($this->encoding !== 'UTF-8') { $input = mb_convert_encoding($input, 'UTF-8', $this->encoding); } $json = json_encode($input, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); if (!$json) { return ''; } $json = trim($json, '"'); // Convert back from UTF-8 if necessary. if ($this->encoding !== 'UTF-8') { //try { $json = mb_convert_encoding($json, $this->encoding, 'UTF-8'); //} catch (Error $e) { // echo 'ERROR CAUGHT. ENCODING: ' . $this->encoding; // return ''; //} } return $json; } } $malicious = 'alert("foo");</script>'; $malicious = 'test'; $utf = new Escaper('UTF-8'); $iso = new Escaper('ISO-8859-1'); echo $utf->js($malicious); echo "\n"; echo $iso->js($malicious); echo "\n"; foreach (mb_list_encodings() as $encoding) { $e = new Escaper($encoding); echo $e->js($malicious); echo ' (' . $encoding . ')'; echo "\n"; } /* mb_internal_encoding('ArmSCII-8'); mb_http_output('ArmSCII-8'); $e = new Escaper('ArmSCII-8'); echo $e->js($malicious); */

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.120.0080.00319.18
8.3.110.0080.00320.94
8.3.100.0090.00324.06
8.3.90.0090.00626.77
8.3.80.0110.00318.68
8.3.70.0170.01019.06
8.3.60.0090.00617.13
8.3.50.0160.00521.46
8.3.40.0120.00319.14
8.3.30.0080.00819.29
8.3.20.0080.00820.75
8.3.10.0090.00021.03
8.3.00.0160.00323.74
8.2.240.0040.00419.22
8.2.230.0060.00322.58
8.2.220.0060.00337.54
8.2.210.0100.01026.77
8.2.200.0030.00617.00
8.2.190.0070.01117.00
8.2.180.0110.00717.00
8.2.170.0160.00622.96
8.2.160.0070.00719.84
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0080.00021.03
8.2.110.0070.00322.39
8.2.100.0040.00818.09
8.2.90.0030.00518.59
8.2.80.0000.00918.53
8.2.70.0070.00318.13
8.2.60.0030.00618.00
8.2.50.0000.00818.41
8.2.40.0060.00320.84
8.2.30.0040.00419.78
8.2.20.0040.00418.60
8.2.10.0080.00018.42
8.2.00.0040.00418.21
8.1.300.0110.00718.70
8.1.290.0090.00030.84
8.1.280.0100.01025.92
8.1.270.0000.00724.66
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0030.00721.18
8.1.230.0060.00621.02
8.1.220.0000.00817.79
8.1.210.0050.00318.77
8.1.200.0060.00317.60
8.1.190.0050.00317.60
8.1.180.0040.00418.10
8.1.170.0030.00518.59
8.1.160.0040.00422.23
8.1.150.0000.00719.11
8.1.140.0040.00419.76
8.1.130.0030.00617.92
8.1.120.0000.00717.56
8.1.110.0040.00417.57
8.1.100.0000.00717.62
8.1.90.0000.00717.72
8.1.80.0000.00717.66
8.1.70.0040.00417.63
8.1.60.0000.00817.80
8.1.50.0080.00017.58
8.1.40.0060.00317.71
8.1.30.0070.00317.79
8.1.20.0000.00817.84
8.1.10.0040.00417.73
8.1.00.0030.00617.80
8.0.300.0000.00720.14
8.0.290.0040.00417.00
8.0.280.0050.00218.50
8.0.270.0070.00017.34
8.0.260.0070.00017.54
8.0.250.0070.00017.20
8.0.240.0000.00717.21
8.0.230.0000.00717.18
8.0.220.0070.00017.08
8.0.210.0000.00717.14
8.0.200.0000.00717.15
8.0.190.0000.00817.14
8.0.180.0030.00717.22
8.0.170.0000.00917.18
8.0.160.0000.00717.16
8.0.150.0000.00717.04
8.0.140.0000.00716.97
8.0.130.0050.00013.48
8.0.120.0000.00817.09
8.0.110.0030.00517.11
8.0.100.0080.00017.11
8.0.90.0040.00417.18
8.0.80.0110.00317.09
8.0.70.0060.00316.96
8.0.60.0040.00416.99
8.0.50.0000.00816.94
8.0.30.0070.01017.32
8.0.20.0100.00917.44
8.0.10.0000.00717.24
8.0.00.0070.01016.76
7.4.330.0030.00315.08
7.4.320.0000.00716.82
7.4.300.0030.00316.68
7.4.290.0030.00316.52
7.4.280.0000.00816.64
7.4.270.0030.00316.65
7.4.260.0000.00816.61
7.4.250.0040.00416.57
7.4.240.0080.00016.74
7.4.230.0000.00716.88
7.4.220.0120.00616.83
7.4.210.0120.00316.85
7.4.200.0040.00416.64
7.4.160.0060.00816.76
7.4.150.0060.01817.40
7.4.140.0140.00617.86
7.4.130.0130.00816.79
7.4.120.0110.01116.70
7.4.110.0070.01116.67
7.4.100.0070.01016.59
7.4.90.0120.01216.71
7.4.80.0100.01319.39
7.4.70.0000.01716.56
7.4.60.0100.00616.60
7.4.50.0030.01216.89
7.4.40.0040.01416.55
7.4.30.0100.00916.68
7.4.20.0130.00616.66
7.4.10.0080.01516.94
7.4.00.0150.00315.84
7.3.330.0000.00513.62
7.3.320.0000.00513.43
7.3.310.0030.00516.45
7.3.300.0000.00716.48
7.3.290.0120.00516.60
7.3.280.0110.00716.58
7.3.270.0110.00617.40
7.3.260.0120.00516.62
7.3.250.0100.00816.72
7.3.240.0080.01016.67
7.3.230.0070.01016.66
7.3.210.0070.01116.58
7.3.200.0000.01616.57
7.3.190.0160.00616.62
7.3.180.0060.00916.55
7.3.170.0110.00516.65
7.3.160.0140.00316.54
7.3.150.0100.01316.65
7.3.140.0150.00616.76
7.3.130.0130.00416.56
7.3.120.0070.01016.79
7.3.110.0120.00616.49
7.3.100.0130.01016.57
7.3.90.0100.01216.51
7.3.80.0070.01316.60
7.3.70.0170.00016.63
7.3.60.0040.01416.58
7.3.50.0090.01116.61
7.3.40.0090.00916.60
7.3.30.0100.00616.53
7.3.20.0160.00716.70
7.3.10.0130.01016.48
7.3.00.0040.01416.62
7.2.330.0170.00717.10
7.2.320.0070.01716.93
7.2.310.0060.01216.80
7.2.300.0100.01016.86
7.2.290.0110.01517.04
7.2.280.0090.01216.80
7.2.270.0060.01316.95
7.2.260.0080.01216.95
7.2.250.0110.01716.88
7.2.240.0070.01416.89
7.2.230.0080.01116.72
7.2.220.0100.01617.13
7.2.210.0150.00616.96
7.2.200.0100.01016.86
7.2.190.0150.01216.96
7.2.180.0030.01916.85
7.2.170.0100.01016.91
7.2.160.0140.00616.92
7.2.150.0110.01116.84
7.2.140.0120.00917.10
7.2.130.0210.00317.05
7.2.120.0100.01016.91
7.2.110.0160.00916.93
7.2.100.0280.00416.94
7.2.90.0130.01316.91
7.2.80.0100.01316.91
7.2.70.0130.01016.96
7.2.60.0050.01316.96
7.2.50.0050.01716.90
7.2.40.0070.01417.07
7.2.30.0110.01716.99
7.2.20.0110.01416.88
7.2.10.0090.01716.90
7.2.00.0100.01016.75
7.1.330.0190.01315.95
7.1.320.0210.01115.85
7.1.310.0280.00715.96
7.1.300.0230.01015.88
7.1.290.0260.00715.95
7.1.280.0210.01215.96
7.1.270.0420.01815.87
7.1.260.0320.01015.83
7.1.250.0210.01415.76
7.1.240.0170.01715.84
7.1.230.0240.01215.92
7.1.220.0140.02015.77
7.1.210.0350.01216.06
7.1.200.0180.00715.99
7.1.190.0350.00615.93
7.1.180.0170.01415.91
7.1.170.0270.01415.90
7.1.160.0410.00715.74
7.1.150.0350.00615.88
7.1.140.0290.00815.92
7.1.130.0230.01115.87
7.1.120.0310.00615.96
7.1.110.0320.00715.91
7.1.100.0280.01116.02
7.1.90.0270.01215.98
7.1.80.0210.01615.79
7.1.70.0150.00716.63
7.1.60.0150.01216.69
7.1.50.0110.01216.59
7.1.40.0190.01516.06
7.1.30.0270.00915.85
7.1.20.0410.00315.68
7.1.10.0220.01215.98
7.1.00.0190.04219.12
7.0.330.0450.00315.45
7.0.320.0220.01215.69
7.0.310.0120.02415.61
7.0.300.0230.00815.59
7.0.290.0460.01515.60
7.0.280.0280.00915.58
7.0.270.0280.00715.60
7.0.260.0180.01715.52
7.0.250.0190.01515.73
7.0.240.0180.01815.65
7.0.230.0250.01115.52
7.0.220.0240.01015.44
7.0.210.0490.00715.46
7.0.200.0140.00815.27
7.0.190.0210.01315.69
7.0.180.0250.00915.64
7.0.170.0280.00615.48
7.0.160.0220.01115.76
7.0.150.0190.01315.42
7.0.140.0160.01615.64
7.0.130.0220.01115.57
7.0.120.0140.02215.64
7.0.110.0250.04017.83
7.0.100.0330.03517.92
7.0.90.0240.03717.87
7.0.80.0380.02717.95
7.0.70.0330.03617.94
7.0.60.0350.04217.88
7.0.50.0330.03417.88
7.0.40.0300.03117.86
7.0.30.0270.03417.87
7.0.20.0280.03617.95
7.0.10.0280.03717.90
7.0.00.0290.03317.93
5.6.400.0310.00015.67
5.6.390.0290.00015.72
5.6.380.0310.00415.73
5.6.370.0300.00715.64
5.6.360.0140.01715.55
5.6.350.0140.01115.52
5.6.340.0260.00515.59
5.6.330.0230.01215.85
5.6.320.0250.01015.86
5.6.310.0210.00915.64
5.6.300.0260.00915.69
5.6.290.0200.01015.72
5.6.280.0160.01415.78
5.6.270.0110.01515.45
5.6.260.0070.03918.27
5.6.250.0140.03718.20
5.6.240.0090.03918.26
5.6.230.0180.03318.51
5.6.220.0160.03418.30
5.6.210.0210.02718.33
5.6.200.0150.03618.21
5.6.190.0160.03518.31
5.6.180.0180.03018.35
5.6.170.0200.03018.26
5.6.160.0240.02318.20
5.6.150.0200.03018.46
5.6.140.0120.04718.41
5.6.130.0120.03718.37
5.6.120.0110.03818.31
5.6.110.0170.03818.29
5.6.100.0160.03718.42
5.6.90.0120.03118.28
5.6.80.0140.02618.05
5.6.70.0080.03318.12
5.6.60.0170.03117.97
5.6.50.0080.03317.94
5.6.40.0120.03918.04
5.6.30.0080.03618.04
5.6.20.0090.03317.89
5.6.10.0120.03017.80
5.6.00.0070.03317.86

preferences:
29.03 ms | 403 KiB | 5 Q