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 substr($texto, 0, 200); print html::trim($texto, 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.0110.00417.25
8.3.50.0090.00823.19
8.3.40.0040.01119.22
8.3.30.0110.00419.29
8.3.20.0050.00320.54
8.3.10.0000.00823.95
8.3.00.0090.00019.48
8.2.180.0130.00316.75
8.2.170.0090.00622.96
8.2.160.0090.00620.55
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0040.00421.39
8.2.110.0040.00419.37
8.2.100.0090.00318.16
8.2.90.0030.00519.51
8.2.80.0040.00417.97
8.2.70.0000.00917.88
8.2.60.0050.00318.18
8.2.50.0040.00418.07
8.2.40.0080.00018.41
8.2.30.0040.00818.38
8.2.20.0080.00017.93
8.2.10.0040.00418.50
8.2.00.0000.00717.88
8.1.280.0100.01025.92
8.1.270.0030.00524.13
8.1.260.0070.00026.35
8.1.250.0060.00328.09
8.1.240.0110.00722.85
8.1.230.0070.00421.10
8.1.220.0060.00318.77
8.1.210.0040.00418.91
8.1.200.0030.00617.73
8.1.190.0050.00317.48
8.1.180.0030.00518.10
8.1.170.0000.00918.86
8.1.160.0050.00322.28
8.1.150.0000.00819.14
8.1.140.0000.00817.77
8.1.130.0030.00318.00
8.1.120.0080.00017.70
8.1.110.0030.00617.68
8.1.100.0040.00417.77
8.1.90.0000.00717.65
8.1.80.0000.00817.68
8.1.70.0000.00817.64
8.1.60.0050.00517.86
8.1.50.0030.00517.69
8.1.40.0000.01017.74
8.1.30.0030.00517.88
8.1.20.0030.00617.97
8.1.10.0040.00417.87
8.1.00.0080.00017.70
8.0.300.0040.00420.30
8.0.290.0050.00217.25
8.0.280.0080.00018.56
8.0.270.0000.00717.57
8.0.260.0000.00717.48
8.0.250.0000.00717.20
8.0.240.0060.00317.17
8.0.230.0080.00017.23
8.0.220.0050.00217.16
8.0.210.0000.00717.20
8.0.200.0030.00317.21
8.0.190.0040.00417.27
8.0.180.0050.00317.21
8.0.170.0080.00017.17
8.0.160.0040.00417.09
8.0.150.0000.00717.20
8.0.140.0040.00417.24
8.0.130.0070.00013.64
8.0.120.0060.00317.16
8.0.110.0050.00217.16
8.0.100.0040.00417.12
8.0.90.0040.00417.20
8.0.80.0150.00617.12
8.0.70.0000.00717.31
8.0.60.0050.00217.18
8.0.50.0000.00717.13
8.0.30.0150.00717.48
8.0.20.0130.00617.40
8.0.10.0040.00417.34
8.0.00.0110.00717.12
7.4.330.0000.00515.47
7.4.320.0060.00016.70
7.4.300.0000.00716.73
7.4.290.0070.00016.86
7.4.280.0000.00716.94
7.4.270.0000.00716.84
7.4.260.0050.00216.74
7.4.250.0040.00416.73
7.4.240.0040.00416.82
7.4.230.0040.00416.55
7.4.220.0120.00616.96
7.4.210.0060.01216.71
7.4.200.0050.00316.88
7.4.160.0110.00516.71
7.4.150.0030.01417.40
7.4.140.0050.01217.86
7.4.130.0130.00316.61
7.4.120.0090.00816.83
7.4.110.0100.00716.68
7.4.100.0100.00716.67
7.4.90.0130.01216.55
7.4.80.0060.01019.39
7.4.70.0090.01216.82
7.4.60.0070.01016.73
7.4.50.0000.00816.97
7.4.40.0040.01216.54
7.4.30.0110.00716.90
7.4.00.0070.00715.33
7.3.330.0030.00313.43
7.3.320.0040.00413.41
7.3.310.0080.00016.64
7.3.300.0070.00016.69
7.3.290.0110.00316.54
7.3.280.0060.01116.63
7.3.270.0030.01417.40
7.3.260.0140.00916.78
7.3.250.0080.00816.85
7.3.240.0130.00616.68
7.3.230.0100.00716.68
7.3.210.0070.01116.56
7.3.200.0100.00716.75
7.3.190.0100.00716.90
7.3.180.0120.00616.72
7.3.170.0120.00816.73
7.3.160.0030.01316.89
7.2.330.0090.00916.81
7.2.320.0030.01817.09
7.2.310.0070.01117.05
7.2.300.0130.00616.94
7.2.290.0120.00616.94
7.2.60.0100.00317.04
7.2.00.0000.01419.61
7.1.200.0000.01515.77
7.1.100.0030.00818.18
7.1.70.0080.00317.07
7.1.60.0070.00417.02
7.1.50.0060.01916.76
7.1.00.0130.06722.54
7.0.200.0060.01016.68
7.0.140.0030.07022.10
7.0.60.0100.08020.08
7.0.50.0170.07318.10
7.0.40.0170.06720.33
7.0.30.0500.07020.19
7.0.20.0400.06020.33
7.0.10.0030.08720.26
7.0.00.0070.07020.16
5.6.280.0070.07021.07
5.6.210.0030.07320.86
5.6.200.0130.08018.24
5.6.190.0130.08320.75
5.6.180.4030.03720.86
5.6.170.0330.07320.64
5.6.160.0100.07320.61
5.6.150.0100.07718.23
5.6.140.0030.04718.31
5.6.130.0000.06018.27
5.6.120.0000.09321.07
5.6.110.0130.06321.18
5.6.100.0070.04721.04
5.6.90.0000.09321.16
5.6.80.0070.05020.48
5.6.70.4070.04320.55
5.5.350.0170.07020.51
5.5.340.0030.08018.16
5.5.330.0030.05020.38
5.5.320.0370.08020.45
5.5.310.0200.04320.45
5.5.300.0070.05018.00
5.5.290.0070.06718.07
5.5.280.0030.05321.02
5.5.270.0130.07320.98
5.5.260.0130.03321.02
5.5.250.0030.04320.54
5.5.240.0100.04320.20
5.4.450.0300.05319.56
5.4.440.0300.04719.64
5.4.430.0400.04319.58
5.4.420.0330.04019.31
5.4.410.0230.04719.56
5.4.400.0270.03719.09
5.4.390.0300.04719.07
5.4.380.0100.06018.55
5.4.370.0170.06018.84
5.4.360.0130.05318.83
5.4.350.0170.05318.58
5.4.340.0130.06318.83
5.4.320.0070.03612.70
5.4.310.0070.04012.70
5.4.300.0030.04112.70
5.4.290.0070.03912.70
5.4.280.0070.03512.60
5.4.270.0070.03712.60
5.4.260.0100.03512.60
5.4.250.0070.03712.59
5.4.240.0050.03712.60
5.4.230.0090.03512.59
5.4.220.0060.03812.59
5.4.210.0060.03612.59
5.4.200.0050.04312.59
5.4.190.0050.05112.58
5.4.180.0100.03312.59
5.4.170.0060.03812.60
5.4.160.0090.04012.60
5.4.150.0050.03912.59
5.4.140.0070.03812.27
5.4.130.0090.03412.27
5.4.120.0060.03512.23
5.4.110.0070.04612.22
5.4.100.0050.04212.22
5.4.90.0080.03512.22
5.4.80.0100.03312.22
5.4.70.0060.03512.21
5.4.60.0050.03812.21
5.4.50.0070.03712.21
5.4.40.0110.04312.20
5.4.30.0080.04512.20
5.4.20.0050.03712.20
5.4.10.0080.03612.20
5.4.00.0060.03811.68
5.3.290.0030.04512.97
5.3.280.0100.04212.90
5.3.270.0090.05012.91
5.3.260.0070.04012.92
5.3.250.0080.04412.91
5.3.240.0080.03612.92
5.3.230.0050.03912.91
5.3.220.0040.04012.88
5.3.210.0080.03812.88
5.3.200.0110.03312.88
5.3.190.0050.03912.88
5.3.180.0080.03412.88
5.3.170.0080.03612.88
5.3.160.0100.04512.88
5.3.150.0080.03712.88
5.3.140.0050.05012.86
5.3.130.0080.05412.86
5.3.120.0130.04912.86
5.3.110.0050.04412.86
5.3.100.0060.04012.35
5.3.90.0080.03912.33
5.3.80.0060.03712.32
5.3.70.0060.04412.32
5.3.60.0050.04012.30
5.3.50.0100.03212.25
5.3.40.0070.03712.25
5.3.30.0060.03512.21
5.3.20.0060.03611.98
5.3.10.0130.03311.96
5.3.00.0060.03711.95
5.2.170.0060.0299.23
5.2.160.0060.0289.22
5.2.150.0090.0269.23
5.2.140.0030.0329.22
5.2.130.0030.0309.18
5.2.120.0060.0309.18
5.2.110.0050.0299.19
5.2.100.0060.0279.19
5.2.90.0050.0299.19
5.2.80.0050.0319.18
5.2.70.0050.0309.18
5.2.60.0040.0339.13
5.2.50.0050.0329.10
5.2.40.0100.0299.08
5.2.30.0100.0329.05
5.2.20.0070.0289.05
5.2.10.0040.0308.95
5.2.00.0050.0318.82
5.1.60.0120.0208.10
5.1.50.0030.0278.09
5.1.40.0040.0278.07
5.1.30.0050.0278.43
5.1.20.0050.0278.45
5.1.10.0100.0248.17
5.1.00.0060.0258.17
5.0.50.0030.0246.65
5.0.40.0030.0226.51
5.0.30.0030.0336.32
5.0.20.0050.0226.29
5.0.10.0080.0286.27
5.0.00.0030.0406.25
4.4.90.0020.0234.78
4.4.80.0040.0214.75
4.4.70.0060.0194.76
4.4.60.0070.0174.75
4.4.50.0020.0234.77
4.4.40.0020.0284.71
4.4.30.0050.0154.76
4.4.20.0040.0194.84
4.4.10.0030.0174.85
4.4.00.0030.0264.76
4.3.110.0040.0154.67
4.3.100.0040.0144.67
4.3.90.0060.0124.64
4.3.80.0060.0254.59
4.3.70.0030.0214.63
4.3.60.0050.0184.63
4.3.50.0060.0164.63
4.3.40.0020.0274.54
4.3.30.0010.0173.30
4.3.20.0030.0163.29
4.3.10.0010.0183.23
4.3.00.0070.01313.42

preferences:
70.72 ms | 401 KiB | 5 Q