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; } } $texto = '<p style="text-align: center">(Vecino de Eiras - Senra)</p> <p style="text-align: center">Falleció el día 13 de Septiembre de 2013 a los 78 años de edad.</p> <p style="text-align: center"><strong>D.E.P.</strong></p> <p style="text-align: left">Su hermana, Consuelo Gómez Maroño; Sobrinos, Nieves, Pilar, Carmen, Fina y Gloria Viqueira Gómez, Tania Fernández Gómez, José, Encarnación, María y Manuel Suárez Gómez, Antonio Cao Gómez y José Gómez Pedreira; Sobrinos políticos, Bisobrinos, Primos y demás familia.</p> <p style="text-align: left">Ruegan una oración por su alma y agradecen la asistencia al funeral de aniversario que por su eterno descanso se celebrará <strong>el Sábado día 13 de Septiembre a las CINCO Y MEDIA de la tarde, en la Iglesia parroquial de SANTA EULALIA DE SENRA.</strong></p> <p style="text-align: left">Favores por los que anticipan las más expresivas gracias.</p> <p style="text-align: left"> </p> <p style="text-align: left"><strong>Senra - Oroso 13 de Septiembre de 2014.</strong></p>'; print html::trim($texto, 200);

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.0110.00716.88
8.3.50.0090.00922.98
8.3.40.0120.00319.06
8.3.30.0120.00619.30
8.3.20.0050.00320.30
8.3.10.0040.00423.61
8.3.00.0040.00419.63
8.2.180.0090.00916.75
8.2.170.0070.00722.96
8.2.160.0140.00420.57
8.2.150.0030.00624.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0050.00321.34
8.2.110.0100.00022.46
8.2.100.0060.00617.97
8.2.90.0040.00419.44
8.2.80.0040.00417.97
8.2.70.0030.00617.75
8.2.60.0040.00418.30
8.2.50.0060.00318.07
8.2.40.0030.00618.41
8.2.30.0030.00918.44
8.2.20.0000.00717.94
8.2.10.0000.00818.36
8.2.00.0000.00818.07
8.1.280.0000.01525.92
8.1.270.0050.00324.12
8.1.260.0040.00426.35
8.1.250.0000.00728.09
8.1.240.0060.00323.96
8.1.230.0000.01119.53
8.1.220.0040.00418.29
8.1.210.0040.00418.77
8.1.200.0070.00317.60
8.1.190.0040.00417.60
8.1.180.0060.00318.10
8.1.170.0000.00918.95
8.1.160.0000.00722.33
8.1.150.0000.00819.16
8.1.140.0040.00417.82
8.1.130.0070.00018.11
8.1.120.0000.00717.75
8.1.110.0060.00317.74
8.1.100.0040.00417.63
8.1.90.0040.00417.79
8.1.80.0050.00217.66
8.1.70.0050.00317.67
8.1.60.0100.00017.78
8.1.50.0040.00417.73
8.1.40.0060.00317.71
8.1.30.0000.00817.79
8.1.20.0040.00417.86
8.1.10.0000.00717.77
8.1.00.0050.00317.72
8.0.300.0060.00318.77
8.0.290.0050.00316.88
8.0.280.0070.00018.80
8.0.270.0050.00317.39
8.0.260.0000.00617.44
8.0.250.0000.00717.24
8.0.240.0090.00017.27
8.0.230.0000.00817.18
8.0.220.0040.00417.27
8.0.210.0030.00317.19
8.0.200.0030.00317.22
8.0.190.0050.00517.29
8.0.180.0040.00417.18
8.0.170.0080.00017.32
8.0.160.0040.00417.12
8.0.150.0000.00717.18
8.0.140.0000.00717.09
8.0.130.0030.00313.65
8.0.120.0000.00817.13
8.0.110.0000.00717.13
8.0.100.0040.00417.16
8.0.90.0070.00017.16
8.0.80.0120.00917.06
8.0.70.0030.00517.20
8.0.60.0080.00017.20
8.0.50.0040.00416.96
8.0.30.0080.01217.40
8.0.20.0170.00517.48
8.0.10.0040.00417.16
8.0.00.0090.00916.95
7.4.330.0000.00515.38
7.4.320.0040.00416.75
7.4.300.0000.00716.73
7.4.290.0050.00316.79
7.4.280.0000.00716.81
7.4.270.0000.00716.95
7.4.260.0070.00016.91
7.4.250.0040.00416.76
7.4.240.0040.00416.83
7.4.230.0050.00216.64
7.4.220.0040.01516.75
7.4.210.0040.01116.73
7.4.200.0040.00416.88
7.4.160.0090.00616.57
7.4.150.0070.01117.40
7.4.140.0090.00817.86
7.4.130.0100.00716.87
7.4.120.0090.00716.82
7.4.110.0110.00816.62
7.4.100.0090.00916.74
7.4.90.0130.00516.75
7.4.80.0120.00819.39
7.4.70.0140.00416.60
7.4.60.0150.00616.68
7.4.50.0060.00316.53
7.4.40.0070.01016.82
7.4.30.0060.01016.68
7.4.10.0090.01016.58
7.4.00.0080.00616.06
7.3.330.0060.00013.41
7.3.320.0040.00413.43
7.3.310.0000.00716.52
7.3.300.0000.00716.55
7.3.290.0130.00316.54
7.3.280.0110.00616.61
7.3.270.0150.00317.40
7.3.260.0060.01216.85
7.3.250.0180.00216.85
7.3.240.0120.00616.61
7.3.230.0030.01316.61
7.3.210.0070.01016.58
7.3.200.0080.01219.39
7.3.190.0070.01016.74
7.3.180.0070.01016.95
7.3.170.0030.01316.83
7.3.160.0130.00316.85
7.3.130.0120.00616.70
7.3.120.0060.01216.55
7.3.110.0030.01316.47
7.3.100.0060.01316.79
7.3.90.0040.00916.78
7.3.80.0080.00816.45
7.3.70.0070.00316.64
7.3.60.0000.01516.68
7.3.50.0060.01016.50
7.3.40.0040.01416.60
7.3.30.0110.00716.54
7.3.20.0060.00618.52
7.3.10.0110.00018.41
7.3.00.0030.01218.46
7.2.330.0090.00917.05
7.2.320.0060.01116.86
7.2.310.0110.00616.77
7.2.300.0130.01016.78
7.2.290.0060.01617.10
7.2.260.0100.01017.06
7.2.250.0030.01616.89
7.2.240.0030.01216.82
7.2.230.0080.00316.75
7.2.220.0080.00816.80
7.2.210.0060.00917.16
7.2.200.0060.00616.80
7.2.190.0130.00316.73
7.2.180.0060.01217.04
7.2.170.0100.01016.84
7.2.160.0030.01316.93
7.2.150.0060.00918.89
7.2.140.0090.00918.52
7.2.130.0040.01118.72
7.2.120.0090.00618.79
7.2.110.0000.01118.66
7.2.100.0070.00718.60
7.2.90.0040.01218.76
7.2.80.0040.00818.73
7.2.70.0030.01318.46
7.2.60.0060.01018.77
7.2.50.0100.00618.74
7.2.40.0030.01318.75
7.2.30.0030.01318.59
7.2.20.0070.01118.48
7.2.10.0060.00618.54
7.2.00.0030.00919.12
7.1.330.0070.00717.55
7.1.320.0080.00417.84
7.1.310.0040.01117.60
7.1.300.0060.01017.71
7.1.290.0080.00617.77
7.1.280.0100.00717.64
7.1.270.0090.00617.79
7.1.260.0100.00717.83
7.1.250.0050.00517.50
7.1.240.0060.00917.55
7.1.230.0030.01417.56
7.1.220.0060.00617.61
7.1.210.0090.00817.41
7.1.200.0080.00817.66
7.1.190.0070.00417.52
7.1.180.0040.00817.63
7.1.170.0000.01417.54
7.1.160.0000.01017.64
7.1.150.0130.00017.68
7.1.140.0120.00317.59
7.1.130.0060.00617.50
7.1.120.0040.01117.60
7.1.110.0030.01417.76
7.1.100.0060.00418.01
7.1.90.0060.00917.68
7.1.80.0120.00617.62
7.1.70.0020.01017.49
7.1.60.0060.01118.48
7.1.50.0070.01117.26
7.1.40.0120.00317.57
7.1.30.0030.01317.71
7.1.20.0080.00317.66
7.1.10.0030.01317.71
7.1.00.0050.04020.07
7.0.330.0030.01017.11
7.0.320.0030.00617.15
7.0.310.0070.00717.53
7.0.300.0070.00717.17
7.0.290.0030.00717.32
7.0.280.0030.01217.27
7.0.270.0060.00617.14
7.0.260.0130.00317.23
7.0.250.0060.00917.08
7.0.240.0030.00917.30
7.0.230.0090.00017.48
7.0.220.0040.00817.16
7.0.210.0090.00317.37
7.0.200.0140.00517.13
7.0.190.0040.00717.30
7.0.180.0060.00617.33
7.0.170.0070.00317.18
7.0.160.0070.00317.39
7.0.150.0030.01017.17
7.0.140.0020.04519.79
7.0.130.0030.01317.29
7.0.120.0040.01117.39
7.0.110.0070.00717.29
7.0.100.0000.01417.22
7.0.90.0110.00417.43
7.0.80.0040.00817.26
7.0.70.0040.00817.11
7.0.60.0090.02018.74
7.0.50.0030.02517.54
7.0.40.0030.04617.73
7.0.30.0150.04917.71
7.0.20.0170.02917.67
7.0.10.0020.03117.80
7.0.00.0050.02517.75
5.6.400.0100.00316.49
5.6.390.0080.00416.45
5.6.380.0030.00916.32
5.6.370.0070.00716.37
5.6.360.0070.00716.13
5.6.350.0030.01316.39
5.6.340.0090.00616.48
5.6.330.0090.00316.06
5.6.320.0100.00316.30
5.6.310.0060.00916.39
5.6.300.0000.01416.45
5.6.290.0070.01016.29
5.6.280.0060.04118.65
5.6.270.0040.00716.05
5.6.260.0070.00716.30
5.6.250.0070.01116.28
5.6.240.0000.01516.36
5.6.230.0110.00416.32
5.6.220.0070.01016.08
5.6.210.0090.04518.50
5.6.200.0130.03217.25
5.6.190.0050.04318.50
5.6.180.1700.02318.45
5.6.170.0150.03618.48
5.6.160.0050.03718.54
5.6.150.0040.03117.27
5.6.140.0080.02017.23
5.6.130.0030.04717.31
5.6.120.0040.05218.74
5.6.110.0070.04118.74
5.6.100.0090.04218.72
5.6.90.0040.04018.89
5.6.80.0070.03518.49
5.6.70.0050.04618.36
5.6.60.0030.01016.17
5.6.50.0040.00816.20
5.6.40.0000.01116.40
5.6.30.0120.00316.22
5.6.20.0040.01116.25
5.6.10.0040.01216.30
5.6.00.0030.00616.43
5.5.380.0070.01016.36
5.5.370.0060.00316.42
5.5.360.0060.00916.21
5.5.350.0080.02418.40
5.5.340.0100.04117.15
5.5.330.0130.04018.27
5.5.320.0220.02218.45
5.5.310.0150.03518.22
5.5.300.0050.02817.04
5.5.290.0040.02917.08
5.5.280.0050.04818.66
5.5.270.0030.03318.56
5.5.260.0020.04418.63
5.5.250.0080.03918.54
5.5.240.0120.04118.27
5.5.230.0090.00616.27
5.5.220.0090.00316.22
5.5.210.0000.01416.34
5.5.200.0120.00316.10
5.5.190.0030.00716.09
5.5.180.0110.00716.04
5.5.170.0040.01116.27
5.5.160.0000.01616.24
5.5.150.0000.01016.30
5.5.140.0040.01416.31
5.5.130.0090.00616.31
5.5.120.0100.00316.08
5.5.110.0070.00416.26
5.5.100.0040.01116.36
5.5.90.0060.01015.97
5.5.80.0070.00716.04
5.5.70.0090.00316.05
5.5.60.0040.00815.95
5.5.50.0060.00316.15
5.5.40.0000.01016.12
5.5.30.0060.00616.33
5.5.20.0100.00716.23
5.5.10.0070.00416.22
5.5.00.0110.00316.22
5.4.450.0120.02716.43
5.4.440.0130.02916.31
5.4.430.0180.02716.39
5.4.420.0370.02316.27
5.4.410.0170.02216.22
5.4.400.0260.02116.04
5.4.390.0130.03316.09
5.4.380.0180.03415.98
5.4.370.0080.03016.01
5.4.360.0110.02815.82
5.4.350.0180.03315.97
5.4.340.0290.03915.94
5.4.330.0040.00813.36
5.4.320.0060.01912.82
5.4.310.0020.02612.85
5.4.300.0050.02713.02
5.4.290.0070.02612.83
5.4.280.0060.02012.77
5.4.270.0070.02212.82
5.4.260.0080.02112.97
5.4.250.0090.02012.80
5.4.240.0040.02612.85
5.4.230.0050.02112.85
5.4.220.0040.02212.83
5.4.210.0080.01912.73
5.4.200.0050.02312.92
5.4.190.0050.02012.73
5.4.180.0050.02612.90
5.4.170.0020.02212.72
5.4.160.0060.02112.86
5.4.150.0030.02112.83
5.4.140.0080.02512.67
5.4.130.0030.02212.63
5.4.120.0040.02112.61
5.4.110.0070.02312.84
5.4.100.0060.02512.63
5.4.90.0050.02312.62
5.4.80.0060.02012.67
5.4.70.0020.02512.69
5.4.60.0070.02312.66
5.4.50.0060.02212.66
5.4.40.0020.02712.69
5.4.30.0050.02212.69
5.4.20.0050.02112.64
5.4.10.0030.02112.64
5.4.00.0080.01812.45
5.3.290.0060.04912.96
5.3.280.0100.04412.89
5.3.270.0090.03712.91
5.3.260.0040.04212.91
5.3.250.0060.04812.91
5.3.240.0070.03612.92
5.3.230.0100.04112.90
5.3.220.0090.04912.88
5.3.210.0110.03712.88
5.3.200.0060.03712.87
5.3.190.0050.04412.87
5.3.180.0060.03612.87
5.3.170.0070.03612.87
5.3.160.0050.03812.88
5.3.150.0070.03612.87
5.3.140.0050.03712.86
5.3.130.0080.03712.86
5.3.120.0070.04112.86
5.3.110.0060.03912.86
5.3.100.0080.03712.35
5.3.90.0050.03712.33
5.3.80.0060.03612.31
5.3.70.0030.04012.31
5.3.60.0060.03612.30
5.3.50.0070.03412.24
5.3.40.0050.04212.25
5.3.30.0090.04312.20
5.3.20.0080.04911.99
5.3.10.0050.03711.96
5.3.00.0030.04011.94
5.2.170.0050.0309.22
5.2.160.0070.0279.22
5.2.150.0020.0339.22
5.2.140.0070.0279.22
5.2.130.0040.0329.18
5.2.120.0080.0369.18
5.2.110.0070.0279.19
5.2.100.0080.0279.19
5.2.90.0050.0369.19
5.2.80.0050.0309.18
5.2.70.0040.0309.18
5.2.60.0060.0299.13
5.2.50.0100.0309.10
5.2.40.0080.0339.08
5.2.30.0060.0359.05
5.2.20.0090.0299.05
5.2.10.0030.0378.96
5.2.00.0070.0388.82
5.1.60.0060.0228.09
5.1.50.0040.0258.09
5.1.40.0050.0238.08
5.1.30.0050.0258.42
5.1.20.0040.0268.45
5.1.10.0070.0328.17
5.1.00.0010.0308.17
5.0.50.0050.0196.65
5.0.40.0040.0306.50
5.0.30.0060.0326.32
5.0.20.0040.0186.29
5.0.10.0050.0176.26
5.0.00.0040.0366.26
4.4.90.0030.0154.78
4.4.80.0030.0144.75
4.4.70.0050.0134.75
4.4.60.0030.0184.76
4.4.50.0050.0234.77
4.4.40.0020.0264.70
4.4.30.0040.0164.76
4.4.20.0040.0174.84
4.4.10.0060.0224.85
4.4.00.0040.0334.76
4.3.110.0030.0154.67
4.3.100.0040.0144.67
4.3.90.0060.0114.64
4.3.80.0020.0274.58
4.3.70.0030.0144.63
4.3.60.0020.0154.63
4.3.50.0010.0164.63
4.3.40.0030.0234.54
4.3.30.0010.0163.30
4.3.20.0030.0153.28
4.3.10.0020.0163.24
4.3.00.0030.01713.42

preferences:
48.46 ms | 401 KiB | 5 Q