3v4l.org

run code in 300+ PHP versions simultaneously
<?php function plaintext_from_HTML($HTML_string) { $document_data = new DOMDocument(); $document_data->loadHTML($HTML_string); return go_through_recursively($document_data->getElementsByTagName('body')[0]); } function go_through_recursively(DomNode $node) { global $buffer; if (!isset($buffer)) $buffer = ''; $node_name = $node->nodeName; $parent_node_name = $node->parentNode->nodeName; $text_contents = $node->textContent; // This is some text content, meaning we are inside an element such as a <p> or <h1>. if ($node_name == '#text') { if ($parent_node_name == 'h1') $buffer .= 'H1: ' . $text_contents . "\n\n"; if ($parent_node_name == 'h2') $buffer .= 'H2: ' . $text_contents . "\n\n"; if ($parent_node_name == 'h3') $buffer .= 'H3: ' . $text_contents . "\n\n"; if ($parent_node_name == 'p') $buffer .= $text_contents . "\n\n"; if ($parent_node_name == 'strong') $buffer .= '**' . $text_contents . '**'; if ($parent_node_name == 'em') $buffer .= '*' . $text_contents . '*'; if ($parent_node_name == 'a') $buffer .= $text_contents . ' ( ' . 'this is supposed to be the URL, but I can\'t figure out how to grab the "href"...' . ' )'; } else // It's an actual element. { if ($node_name == 'br') $buffer .= "\n"; if ($node_name == 'hr') $buffer .= '---------------' . "\n" . "\n"; } if ($node->childNodes) { foreach ($node->childNodes as $node) go_through_recursively($node); } return $buffer; } $HTML_string = ' <h1>Test of h1</h1> <p>This is a p test.</p> <h2>Test of h2</h2> <p>This is a p test with a <strong>strong emphasis</strong> followed by this.</p> <h3>Test of h3</h3> <p>This here is a link: <a href="http://www.example.com/1">Example.com</a>.<br> And this is a linebreak.</p> <p>Another paragraph, followed by a horizontal line:</p> <hr> <p>A final paragraph with <a href="http://www.example.com/2"><em>some emphasis</em> inside a link</a>.</p> '; echo plaintext_from_HTML($HTML_string); /* DESIRED/EXPECTED OUTPUT: H1: Test of h1 This is a p test. H2: Test of h2 This is a p test with a **strong emphasis** followed by this. H3: Test of h3 This here is a link: Example.com ( http://www.example.com/1 ). And this is a linebreak. Another paragraph, followed by a horizontal line: --------------- A final paragraph with *some emphasis* inside a link ( http://www.example.com/2 ). ACTUAL OUTPUT: H1: Test of h1 This is a p test. H2: Test of h2 This is a p test with a **strong emphasis** followed by this. H3: Test of h3 This here is a link: Example.com ( this is supposed to be the URL, but I can't figure out how to grab the "href"... ). And this is a linebreak. Another paragraph, followed by a horizontal line: --------------- A final paragraph with *some emphasis* inside a link ( this is supposed to be the URL, but I can't figure out how to grab the "href"... ). */

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.00718.43
8.3.50.0070.00918.43
8.3.40.0120.00919.03
8.3.30.0070.01119.09
8.3.20.0030.00522.18
8.3.10.0080.00021.16
8.3.00.0050.00322.15
8.2.180.0090.00925.92
8.2.170.0070.01022.96
8.2.160.0150.00022.33
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0090.00026.16
8.2.120.0050.00326.16
8.2.110.0060.00321.19
8.2.100.0040.00819.89
8.2.90.0040.00419.50
8.2.80.0030.00617.97
8.2.70.0080.00017.75
8.2.60.0050.00318.15
8.2.50.0030.00718.07
8.2.40.0000.00818.41
8.2.30.0040.00420.04
8.2.20.0040.00418.37
8.2.10.0000.00819.26
8.2.00.0040.00418.35
8.1.280.0160.00625.92
8.1.270.0000.00823.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00322.86
8.1.230.0070.00419.19
8.1.220.0000.00818.14
8.1.210.0030.00518.77
8.1.200.0120.00017.60
8.1.190.0030.00617.60
8.1.180.0000.00918.10
8.1.170.0000.00819.08
8.1.160.0030.00619.24
8.1.150.0000.00719.14
8.1.140.0000.00820.51
8.1.130.0070.00020.56
8.1.120.0000.00817.73
8.1.110.0040.00417.69
8.1.100.0050.00217.66
8.1.90.0070.00017.70
8.1.80.0070.00417.68
8.1.70.0000.00717.68
8.1.60.0030.00817.71
8.1.50.0060.00317.80
8.1.40.0030.00617.75
8.1.30.0040.00417.98
8.1.20.0080.00017.92
8.1.10.0040.00417.86
8.1.00.0060.00317.67
8.0.300.0030.00518.77
8.0.290.0000.00717.00
8.0.280.0050.00318.68
8.0.270.0050.00217.50
8.0.260.0030.00318.55
8.0.250.0000.00717.29
8.0.240.0070.00017.29
8.0.230.0000.00717.33
8.0.220.0030.00317.13
8.0.210.0060.00317.27
8.0.200.0000.00617.24
8.0.190.0000.00817.23
8.0.180.0060.00317.21
8.0.170.0060.00317.11
8.0.160.0040.00417.16
8.0.150.0040.00417.02
8.0.140.0000.00717.20
8.0.130.0030.00313.67
8.0.120.0000.00817.12
8.0.110.0040.00417.17
8.0.100.0040.00416.98
8.0.90.0070.00016.97
8.0.80.0090.01217.13
8.0.70.0050.00317.10
8.0.60.0070.00017.14
8.0.50.0040.00417.20
8.0.30.0090.00817.37
8.0.20.0120.00917.39
8.0.10.0000.00817.29
8.0.00.0140.00916.94
7.4.330.0020.00215.55
7.4.320.0000.00716.70
7.4.300.0030.00316.86
7.4.290.0080.00316.82
7.4.280.0050.00316.69
7.4.270.0080.00316.87
7.4.260.0070.00016.85
7.4.250.0070.00016.75
7.4.240.0030.00316.87
7.4.230.0030.00316.55
7.4.220.0030.00516.93
7.4.210.0070.00816.87
7.4.200.0000.00716.77
7.4.160.0100.00916.70
7.4.140.0090.00917.86
7.4.130.0140.00416.67
7.4.120.0160.00616.96
7.4.110.0070.01716.79
7.4.100.0030.01416.98
7.4.90.0060.01016.59
7.4.80.0160.00419.39
7.4.70.0100.00716.86
7.4.60.0070.01616.74
7.4.50.0060.00616.65
7.4.40.0080.01116.74
7.4.10.0030.01615.28
7.4.00.0060.01114.96
7.3.330.0020.00313.45
7.3.320.0000.00613.58
7.3.310.0000.00716.64
7.3.300.0000.00716.57
7.3.290.0030.00316.50
7.3.280.0090.00716.56
7.3.260.0100.00816.74
7.3.240.0080.00916.73
7.3.230.0060.01316.70
7.3.210.0110.00716.54
7.3.200.0100.00716.72
7.3.190.0140.00316.52
7.3.180.0140.00316.59
7.3.170.0100.00716.81
7.3.160.0000.01916.72
7.3.130.0030.01415.29
7.3.120.0130.00315.05
7.3.110.0090.00614.89
7.3.100.0060.00915.01
7.3.90.0060.01014.97
7.3.80.0060.00615.04
7.3.70.0030.01314.99
7.3.60.0090.00314.84
7.3.50.0100.00515.01
7.3.40.0060.00614.82
7.3.30.0070.00714.88
7.3.20.0060.00916.66
7.3.10.0070.00316.83
7.3.00.0130.00516.70
7.2.330.0100.00716.71
7.2.320.0070.01016.71
7.2.310.0120.00417.01
7.2.300.0100.00616.89
7.2.290.0030.01716.79
7.2.260.0060.01215.10
7.2.250.0030.01615.03
7.2.240.0030.00915.35
7.2.230.0060.00915.45
7.2.220.0060.01015.29
7.2.210.0080.00415.24
7.2.200.0060.00915.33
7.2.190.0030.01015.03
7.2.180.0030.00815.25
7.2.170.0100.01015.12
7.2.160.0060.00415.34
7.2.150.0090.00516.87
7.2.140.0100.00817.08
7.2.130.0090.01017.04
7.2.120.0100.01016.97
7.2.110.0080.00417.03
7.2.100.0030.01016.82
7.2.90.0090.01116.99
7.2.80.0040.01017.13
7.2.70.0100.00517.15
7.2.60.0080.00816.97
7.2.50.0060.00817.10
7.2.40.0070.00617.01
7.2.30.0050.01117.18
7.2.20.0090.00617.14
7.2.10.0060.01016.95
7.2.00.0120.00617.02
7.1.330.0030.00916.00
7.1.320.0040.01216.12
7.1.310.0100.00715.91
7.1.300.0060.01015.64
7.1.290.0060.00915.92
7.1.280.0070.00415.94
7.1.270.0100.00715.70
7.1.260.0060.00415.97
7.1.250.0120.00415.84
7.1.240.0030.01315.98
7.1.230.0060.00615.95
7.1.220.0090.00616.00
7.1.210.0030.00715.92
7.1.200.0080.00815.87
7.1.190.0120.00315.85
7.1.180.0060.00915.68
7.1.170.0000.01016.01
7.1.160.0060.00815.62
7.1.150.0070.01115.79
7.1.140.0000.01615.91
7.1.130.0000.01516.07
7.1.120.0030.01015.81
7.1.110.0000.00815.71
7.1.100.0000.01015.96
7.1.90.0100.00315.66
7.1.80.0080.00515.92
7.1.70.0120.00416.02
7.1.60.0070.00715.92
7.1.50.0030.01315.95
7.1.40.0120.00015.82
7.1.30.0000.01315.79
7.1.20.0000.00915.95
7.1.10.0040.00415.94
7.1.00.0030.00615.92

preferences:
59.38 ms | 401 KiB | 5 Q