3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Html{ protected $reachedLimit = false, $totalLen = 0, $maxLen = 25, $toRemove = array(); public static function trim($html, $maxLen = 25){ $dom = new DomDocument(); $dom->loadHTML($html); $html = new static(); $toRemove = $html->walk($dom, $maxLen); // remove any nodes that passed our limit foreach($toRemove as $child) $child->parentNode->removeChild($child); // remove wrapper tags added by DD (doctype, html...) if(version_compare(PHP_VERSION, '5.3.6') < 0){ // http://stackoverflow.com/a/6953808/1058140 $dom->removeChild($dom->firstChild); $dom->replaceChild($dom->firstChild->firstChild->firstChild, $dom->firstChild); return $dom->saveHTML(); } return $dom->saveHTML($dom->getElementsByTagName('body')->item(0)); } protected function walk(DomNode $node, $maxLen){ if($this->reachedLimit){ $this->toRemove[] = $node; }else{ // only text nodes should have text, // so do the splitting here if($node instanceof DomText){ $this->totalLen += $nodeLen = strlen($node->nodeValue); // use mb_strlen / mb_substr for UTF-8 support if($this->totalLen > $maxLen){ $node->nodeValue = substr($node->nodeValue, 0, $nodeLen - ($this->totalLen - $maxLen)) . '...'; $this->reachedLimit = true; } } // if node has children, walk its child elements if(isset($node->childNodes)) foreach($node->childNodes as $child) $this->walk($child, $maxLen); } return $this->toRemove; } } print html::trim('<p>I äöücan haz <strong> html trim </strong>', 14);

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.0060.00916.59
8.3.50.0100.00722.16
8.3.40.0040.01118.96
8.3.30.0040.01519.27
8.3.20.0040.00420.38
8.3.10.0000.00823.73
8.3.00.0040.00419.50
8.2.180.0130.01016.63
8.2.170.0150.00022.96
8.2.160.0130.00020.60
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0000.00921.14
8.2.110.0000.01022.21
8.2.100.0110.00020.66
8.2.90.0030.00519.51
8.2.80.0040.00417.97
8.2.70.0040.00418.00
8.2.60.0000.00918.03
8.2.50.0030.00718.07
8.2.40.0060.00320.11
8.2.30.0000.00818.61
8.2.20.0080.00018.03
8.2.10.0050.00318.48
8.2.00.0040.00418.10
8.1.280.0040.01125.92
8.1.270.0060.00324.09
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00722.22
8.1.230.0120.00019.45
8.1.220.0050.00318.04
8.1.210.0060.00318.77
8.1.200.0100.00017.72
8.1.190.0000.00817.73
8.1.180.0040.00418.10
8.1.170.0080.00418.90
8.1.160.0050.00322.36
8.1.150.0020.00518.98
8.1.140.0050.00317.65
8.1.130.0000.00718.02
8.1.120.0040.00417.67
8.1.110.0080.00017.70
8.1.100.0040.00417.64
8.1.90.0000.00817.65
8.1.80.0000.00717.66
8.1.70.0030.00317.66
8.1.60.0040.00417.91
8.1.50.0030.00617.70
8.1.40.0050.00317.69
8.1.30.0040.00417.84
8.1.20.0040.00417.90
8.1.10.0060.00317.79
8.1.00.0040.00417.69
8.0.300.0040.00418.77
8.0.290.0000.00717.13
8.0.280.0040.00418.79
8.0.270.0000.00717.43
8.0.260.0000.00717.48
8.0.250.0030.00317.30
8.0.240.0040.00417.27
8.0.230.0050.00317.20
8.0.220.0080.00017.14
8.0.210.0020.00517.16
8.0.200.0000.00617.20
8.0.190.0040.00717.33
8.0.180.0000.00817.20
8.0.170.0030.00617.22
8.0.160.0040.00317.08
8.0.150.0040.00417.14
8.0.140.0020.00517.14
8.0.130.0000.00813.66
8.0.120.0030.00517.25
8.0.110.0040.00417.27
8.0.100.0040.00417.11
8.0.90.0040.00417.30
8.0.80.0000.01617.30
8.0.70.0040.00417.04
8.0.60.0000.00817.35
8.0.50.0000.00717.20
8.0.30.0130.00517.44
8.0.20.0110.01217.40
8.0.10.0040.00417.39
8.0.00.0070.01116.92
7.4.330.0000.00615.25
7.4.320.0000.00616.92
7.4.300.0000.00616.86
7.4.290.0000.00716.93
7.4.280.0070.00016.87
7.4.270.0070.00016.65
7.4.260.0030.00316.70
7.4.250.0070.00016.82
7.4.240.0040.00316.82
7.4.230.0050.00216.63
7.4.220.0110.00716.71
7.4.210.0120.00416.78
7.4.200.0000.00817.01
7.4.160.0060.01016.75
7.4.150.0110.00717.40
7.4.140.0120.00517.86
7.4.130.0100.00616.87
7.4.120.0070.01016.95
7.4.110.0030.01316.67
7.4.100.0140.00416.50
7.4.90.0100.00716.75
7.4.80.0110.00819.39
7.4.70.0120.00916.78
7.4.60.0090.01216.63
7.4.50.0030.00616.78
7.4.40.0030.01316.67
7.4.30.0130.00316.92
7.4.10.0060.00915.24
7.4.00.0060.01115.15
7.3.330.0000.00513.51
7.3.320.0030.00313.53
7.3.310.0040.00416.65
7.3.300.0000.00716.65
7.3.290.0060.00916.57
7.3.280.0070.00916.54
7.3.270.0050.01117.40
7.3.260.0180.00516.68
7.3.250.0070.01016.80
7.3.240.0030.01516.52
7.3.230.0120.00616.55
7.3.210.0110.00716.77
7.3.200.0090.00919.39
7.3.190.0030.01816.97
7.3.180.0030.01216.77
7.3.170.0070.00916.87
7.3.160.0070.01016.51
7.3.130.0020.01414.68
7.3.120.0060.00815.01
7.3.110.0070.01115.04
7.3.100.0080.00415.07
7.3.90.0040.00714.96
7.3.80.0030.00914.98
7.3.70.0110.00415.09
7.3.60.0030.00614.87
7.3.50.0060.00615.05
7.3.40.0070.00714.70
7.3.30.0030.00714.90
7.3.20.0000.01116.76
7.3.10.0040.01016.88
7.3.00.0050.01016.86
7.2.330.0030.01516.94
7.2.320.0060.01917.15
7.2.310.0060.01816.97
7.2.300.0000.01717.03
7.2.290.0040.01416.80
7.2.260.0070.01015.55
7.2.250.0030.01415.46
7.2.240.0070.00714.98
7.2.230.0080.00815.22
7.2.220.0070.01015.36
7.2.210.0070.00715.39
7.2.200.0090.00615.48
7.2.190.0040.01115.17
7.2.180.0000.01115.11
7.2.170.0030.00615.09
7.2.160.0030.01015.34
7.2.150.0030.01317.14
7.2.140.0120.00016.98
7.2.130.0070.00717.19
7.2.120.0070.00917.05
7.2.110.0020.01216.98
7.2.100.0080.00517.03
7.2.90.0060.00716.88
7.2.80.0070.00816.82
7.2.70.0060.00816.98
7.2.60.0090.01216.99
7.2.50.0050.00817.05
7.2.40.0080.00617.17
7.2.30.0040.00817.01
7.2.20.0040.01116.94
7.2.10.0070.00617.00
7.2.00.0040.01017.95
7.1.330.0000.01316.14
7.1.320.0060.00916.07
7.1.310.0000.01315.86
7.1.300.0070.00716.14
7.1.290.0030.00615.98
7.1.280.0030.00815.91
7.1.270.0040.00815.83
7.1.260.0030.01315.88
7.1.250.0050.00716.01
7.1.240.0080.00516.00
7.1.230.0070.01015.69
7.1.220.0050.00515.74
7.1.210.0070.00715.96
7.1.200.0060.00715.85
7.1.190.0030.00615.86
7.1.180.0030.01016.06
7.1.170.0030.00916.02
7.1.160.0110.00315.95
7.1.150.0070.00715.84
7.1.140.0040.00715.87
7.1.130.0040.00815.82
7.1.120.0030.00615.92
7.1.110.0080.00416.14
7.1.100.0050.00917.13
7.1.90.0040.01116.09
7.1.80.0070.01015.80
7.1.70.0040.00716.56
7.1.60.0070.01317.92
7.1.50.0110.01416.43
7.1.40.0070.00716.00
7.1.30.0030.01016.11
7.1.20.0050.00515.83
7.1.10.0030.01016.10
7.1.00.0080.03719.13
7.0.330.0060.00615.49
7.0.320.0030.00915.54
7.0.310.0150.00015.60
7.0.300.0080.00415.57
7.0.290.0080.00415.53
7.0.280.0060.00615.29
7.0.270.0040.01115.36
7.0.260.0110.00315.25
7.0.250.0060.00615.53
7.0.240.0100.00715.39
7.0.230.0100.00715.57
7.0.220.0060.00315.71
7.0.210.0070.00715.49
7.0.200.0020.00816.12
7.0.190.0150.00015.27
7.0.180.0040.00815.58
7.0.170.0030.01015.60
7.0.160.0050.00315.62
7.0.150.0000.01515.24
7.0.140.0030.04218.82
7.0.130.0130.00015.37
7.0.120.0000.01115.66
7.0.110.0030.00915.59
7.0.100.0060.00615.45
7.0.90.0030.01015.56
7.0.80.0030.01015.63
7.0.70.0030.01015.50
7.0.60.0030.02718.65
7.0.50.0050.03718.77
7.0.40.0030.02816.87
7.0.30.0020.03116.90
7.0.20.0030.02516.81
7.0.10.0030.03516.91
7.0.00.0050.02317.00
5.6.400.0130.00014.79
5.6.390.0060.00614.88
5.6.380.0070.00714.59
5.6.370.0050.00514.47
5.6.360.0100.00314.78
5.6.350.0130.00314.46
5.6.340.0070.00714.89
5.6.330.0040.00714.86
5.6.320.0090.00614.55
5.6.310.0090.00314.68
5.6.300.0070.00714.32
5.6.290.0060.00614.81
5.6.280.0030.04117.99
5.6.270.0040.00814.77
5.6.260.0030.01314.46
5.6.250.0000.01414.77
5.6.240.0040.01114.48
5.6.230.0030.00614.60
5.6.220.0030.01214.88
5.6.210.0030.03317.78
5.6.200.0000.04117.83
5.6.190.0050.03117.93
5.6.180.0050.02317.98
5.6.170.0050.02517.90
5.6.160.0070.03217.87
5.6.150.0030.02017.76
5.6.140.0030.03017.82
5.6.130.0030.02717.87
5.6.120.0030.02317.81
5.6.110.0020.02217.86
5.6.100.0050.02017.89
5.6.90.0050.02217.82
5.6.80.0040.01717.39
5.6.70.0000.03017.54
5.6.60.0070.02217.56
5.6.50.0020.02117.51
5.6.40.0000.02217.53
5.6.30.0050.01917.43
5.6.20.0030.02817.52
5.6.10.0020.02417.49
5.6.00.0070.03817.42
5.5.380.0040.00814.45
5.5.370.0060.01014.84
5.5.360.0040.01114.67
5.5.350.0070.01917.47
5.5.340.0070.02817.70
5.5.330.0060.03517.74
5.5.320.0030.02917.73
5.5.310.0120.02017.63
5.5.300.0070.02117.86
5.5.290.0000.03017.68
5.5.280.0050.01817.72
5.5.270.0000.02517.61
5.5.260.0020.02317.84
5.5.250.0000.02317.80
5.5.240.0020.02217.32
5.5.230.0080.02117.38
5.5.220.0020.01917.46
5.5.210.0090.02117.25
5.5.200.0050.01617.31
5.5.190.0050.01917.20
5.5.180.0030.02517.35
5.5.170.0040.00714.71
5.5.160.0050.01817.53
5.5.150.0060.02217.33
5.5.140.0040.04017.31
5.5.130.0030.04017.49
5.5.120.0070.03517.38
5.5.110.0050.04117.28
5.5.100.0050.04217.40
5.5.90.0050.04017.31
5.5.80.0070.04017.43
5.5.70.0060.04117.16
5.5.60.0050.04017.23
5.5.50.0050.03417.30
5.5.40.0050.04017.21
5.5.30.0040.04417.38
5.5.20.0050.03517.14
5.5.10.0040.03017.37
5.5.00.0070.04217.36
5.4.450.0050.01815.85
5.4.440.0040.01915.90
5.4.430.0020.02015.80
5.4.420.0000.02315.89
5.4.410.0030.01815.76
5.4.400.0000.02315.69
5.4.390.0020.02115.73
5.4.380.0000.02515.64
5.4.370.0050.01615.63
5.4.360.0050.01815.58
5.4.350.0040.02215.74
5.4.340.0030.02315.71
5.4.330.0030.00912.18
5.4.320.0090.03515.74
5.4.310.0000.02515.66
5.4.300.0000.02215.71
5.4.290.0030.01715.67
5.4.280.0030.04215.67
5.4.270.0020.04515.70
5.4.260.0030.04315.74
5.4.250.0060.03715.71
5.4.240.0050.03915.74
5.4.230.0010.04515.72
5.4.220.0020.04415.63
5.4.210.0020.04215.66
5.4.200.0030.04215.58
5.4.190.0020.04115.58
5.4.180.0020.03715.68
5.4.170.0020.04015.59
5.4.160.0030.03715.71
5.4.150.0050.03715.65
5.4.140.0080.04014.37
5.4.130.0050.03914.25
5.4.120.0000.04314.38
5.4.110.0050.02614.33
5.4.100.0050.03814.42
5.4.90.0020.04314.32
5.4.80.0070.03614.40
5.4.70.0020.03214.32
5.4.60.0040.03114.42
5.4.50.0020.03114.33
5.4.40.0050.03614.41
5.4.30.0070.03714.39
5.4.20.0050.03814.33
5.4.10.0020.03414.32
5.4.00.0020.03914.11
5.3.290.0050.03013.45
5.3.280.0070.03813.49
5.3.270.0070.04113.47
5.3.260.0050.04213.46
5.3.250.0040.03713.40
5.3.240.0070.02713.52
5.3.230.0040.04013.46
5.3.220.0040.03913.44
5.3.210.0030.03213.44
5.3.200.0000.04413.44
5.3.190.0030.04213.44
5.3.180.0080.03813.41
5.3.170.0030.04213.46
5.3.160.0020.02913.48
5.3.150.0050.03213.45
5.3.140.0050.02513.45
5.3.130.0030.04513.39
5.3.120.0040.04413.34
5.3.110.0030.04013.45
5.3.100.0050.03513.18
5.3.90.0040.03613.18
5.3.80.0000.04013.14
5.3.70.0080.03813.22
5.3.60.0050.03813.06
5.3.50.0020.04113.09
5.3.40.0070.03313.16
5.3.30.0060.03213.11
5.3.20.0020.03013.01
5.3.10.0030.03713.02
5.3.00.0060.03712.88
5.2.170.0070.05711.19
5.2.160.0030.06011.13
5.2.150.0030.05711.18
5.2.140.0000.06711.12
5.2.130.0070.05311.15
5.2.120.0030.05711.14
5.2.110.0070.05311.16
5.2.100.0030.05711.20
5.2.90.0030.05711.15
5.2.80.0070.05711.14
5.2.70.0030.05711.10
5.2.60.0030.06011.15
5.2.50.0070.04710.87
5.2.40.0030.05711.05
5.2.30.0000.06710.97
5.2.20.0030.06010.80
5.2.10.0000.05310.71
5.2.00.0000.06310.74
5.1.60.0030.05310.39
5.1.50.0000.05310.39
5.1.40.0030.05010.39
5.1.30.0070.05010.42
5.1.20.0000.05710.39
5.1.10.0070.05310.39
5.1.00.0030.05010.39
5.0.50.0000.04310.39
5.0.40.0000.04010.39
5.0.30.0000.06710.39
5.0.20.0000.03710.39
5.0.10.0000.04010.39
5.0.00.0030.04710.39
4.4.90.0000.03310.39
4.4.80.0030.03310.39
4.4.70.0000.03010.39
4.4.60.0030.03310.39
4.4.50.0000.03710.39
4.4.40.0000.05310.39
4.4.30.0030.03710.39
4.4.20.0000.03310.39
4.4.10.0000.03710.39
4.4.00.0000.05310.39
4.3.110.0070.03310.39
4.3.100.0000.03710.39
4.3.90.0000.03710.39
4.3.80.0100.04010.39
4.3.70.0030.03010.39
4.3.60.0000.03010.39
4.3.50.0000.03710.39
4.3.40.0030.03710.39
4.3.30.0000.03710.39
4.3.20.0000.03710.39
4.3.10.0000.03710.39
4.3.00.0000.03310.39

preferences:
55.79 ms | 401 KiB | 5 Q