3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML Meet God's General Kathryn Kuhlman. <br> <img class="lazy_responsive" title="Kathryn Kuhlman - iUseFaith.com" src="https://www.iusefaith.com/ojm_thumbnail/1000/32f808f79011a7c0bd1ffefc1365c856.jpg" alt="Kathryn Kuhlman - iUseFaith.com" width="1600" height="517" /> <br> Follow <a href="https://www.iusefaith.com/en-354" title="Kathryn Kuhlman">Kathryn Kuhlman</a> <br> Max KANTCHEDE HTML; $keywords = [ 'Kathryn Kuhlman' => 'https://www.example.com/en-354', 'Max KANTCHEDE' => 'https://www.example.com/MaxKANTCHEDE', 'eneral' => 'https://www.example.com/this-is-not-used', ]; libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); $lookup = []; $regexNeedles = []; foreach ($keywords as $name => $link) { $lookup[strtolower($name)] = $link; $regexNeedles[] = preg_quote($name, '~'); } $pattern = '~\b(' . implode('|', $regexNeedles) . ')\b~i' ; foreach($xpath->query('//*[not(self::img or self::a)]/text()') as $textNode) { $newNodes = []; $hasReplacement = false; foreach (preg_split($pattern, $textNode->nodeValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $fragment) { $fragmentLower = strtolower($fragment); if (isset($lookup[$fragmentLower])) { $hasReplacement = true; $a = $dom->createElement('a'); $a->setAttribute('href', $lookup[$fragmentLower]); $a->setAttribute('title', $fragment); $a->nodeValue = $fragment; $newNodes[] = $a; } else { $newNodes[] = $dom->createTextNode($fragment); } } if ($hasReplacement) { $newFragment = $dom->createDocumentFragment(); foreach ($newNodes as $newNode) { $newFragment->appendChild($newNode); } $textNode->parentNode->replaceChild($newFragment, $textNode); } } echo substr(trim($dom->saveHTML()), 3, -4);

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.4.140.0150.00618.09
8.4.130.0140.00619.21
8.4.120.0140.00622.83
8.4.110.0120.01019.10
8.4.100.0110.01118.20
8.4.90.0100.01020.94
8.4.80.0100.00821.09
8.4.70.0120.00919.19
8.4.60.0120.00821.13
8.4.50.0080.00822.67
8.4.40.0200.00020.30
8.4.30.0070.01320.68
8.4.20.0130.00918.27
8.4.10.0170.00321.04
8.3.270.0090.01117.15
8.3.260.0110.00916.96
8.3.250.0110.00817.52
8.3.240.0080.01317.15
8.3.230.0090.00717.12
8.3.220.0040.00419.54
8.3.210.0100.01018.69
8.3.200.0100.00617.35
8.3.190.0100.00917.60
8.3.180.0120.00719.36
8.3.170.0030.01618.99
8.3.160.0090.00917.60
8.3.150.0120.00619.34
8.3.140.0070.01117.55
8.3.130.0060.00318.72
8.3.120.0100.00021.13
8.3.110.0040.00420.94
8.3.100.0050.00324.06
8.3.90.0040.01126.77
8.3.80.0090.00017.25
8.3.70.0090.00617.00
8.3.60.0070.01117.38
8.3.50.0100.00724.91
8.3.40.0120.00920.80
8.3.30.0070.00719.21
8.3.20.0080.00024.18
8.3.10.0140.00324.66
8.3.00.0030.00526.16
8.2.290.0030.00517.64
8.2.280.0120.01118.79
8.2.270.0170.00317.71
8.2.260.0090.00617.69
8.2.250.0040.00418.98
8.2.240.0060.00319.48
8.2.230.0060.00322.58
8.2.220.0090.00037.54
8.2.210.0150.00326.77
8.2.200.0060.00317.38
8.2.190.0110.01117.13
8.2.180.0100.01025.92
8.2.170.0160.00619.76
8.2.160.0030.01322.96
8.2.150.0060.00325.66
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0040.00819.52
8.2.110.0070.00420.88
8.2.100.0080.00318.47
8.2.90.0030.00518.25
8.2.80.0000.00917.97
8.2.70.0030.00518.54
8.2.60.0050.00318.25
8.2.50.0090.00318.07
8.2.40.0030.00618.85
8.2.30.0050.00318.53
8.2.20.0050.00318.42
8.2.10.0040.00419.71
8.2.00.0040.00419.70
8.1.330.0140.00616.62
8.1.320.0110.00916.67
8.1.310.0120.00618.84
8.1.300.0030.00620.36
8.1.290.0090.00318.88
8.1.280.0040.01125.92
8.1.270.0040.00424.39
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0090.00322.38
8.1.230.0080.00322.32
8.1.220.0040.00418.16
8.1.210.0050.00518.77
8.1.200.0030.00617.85
8.1.190.0100.00017.75
8.1.180.0040.00418.10
8.1.170.0060.00319.09
8.1.160.0040.00419.27
8.1.150.0050.00319.19
8.1.140.0070.00019.37
8.1.130.0030.00320.48
8.1.120.0080.00018.04
8.1.110.0050.00317.89
8.1.100.0060.00318.00
8.1.90.0000.00817.85
8.1.80.0000.00917.93
8.1.70.0000.00717.94
8.1.60.0030.00518.05
8.1.50.0000.00917.93
8.1.40.0070.00318.09
8.1.30.0030.00518.11
8.1.20.0030.00618.16
8.1.10.0040.00418.03
8.1.00.0040.00417.99
8.0.300.0000.00922.00
8.0.290.0000.00917.38
8.0.280.0000.00718.82
8.0.270.0050.00318.58
8.0.260.0030.00318.85
8.0.250.0040.00417.43
8.0.240.0040.00417.55
8.0.230.0030.00317.45
8.0.220.0030.00317.48
8.0.210.0040.00417.46
8.0.200.0030.00517.44
8.0.190.0070.00017.41
8.0.180.0050.00217.37
8.0.170.0000.01017.42
8.0.160.0030.00617.52
8.0.150.0050.00317.30
8.0.140.0070.00317.45
8.0.130.0030.00313.89
8.0.120.0050.00317.32
8.0.110.0040.00417.50
8.0.100.0080.00017.48
8.0.90.0040.00417.35
8.0.80.0100.00917.50
8.0.70.0030.00617.41
8.0.60.0030.00517.55
8.0.50.0000.00817.41
8.0.30.0070.01917.70
8.0.20.0120.00717.70
8.0.10.0030.00617.43
8.0.00.0160.01017.34
7.4.330.0050.00015.55
7.4.320.0070.00017.07
7.4.300.0000.00617.04
7.4.290.0030.00317.16
7.4.280.0070.00317.09
7.4.270.0000.00717.17
7.4.260.0030.00317.08
7.4.250.0040.00417.16
7.4.240.0030.00617.15
7.4.230.0070.00017.18
7.4.220.0030.00316.91
7.4.210.0110.00417.20
7.4.200.0020.00517.00
7.4.130.0120.01317.04
7.4.120.0140.00317.17
7.4.110.0070.01117.10
7.4.100.0070.01017.20
7.4.90.0080.01217.11
7.4.80.0140.00416.95
7.4.70.0100.00716.98
7.4.60.0120.00616.97
7.4.50.0150.00316.97
7.4.40.0090.00917.07
7.4.30.0110.01117.11
7.4.20.0120.00917.00
7.4.10.0140.00716.89
7.4.00.0120.00616.87
7.3.330.0170.00216.89
7.3.320.0000.00613.73
7.3.310.0020.00517.00
7.3.300.0030.00316.88
7.3.290.0080.01016.91
7.3.260.0110.00717.13
7.3.230.0070.01116.82
7.3.220.0100.00617.02
7.3.210.0090.00916.98
7.3.200.0170.00016.89
7.3.190.0090.00916.97
7.3.180.0100.00716.98
7.3.170.0110.00616.87
7.3.160.0100.01017.05
7.3.150.0140.00717.14
7.3.140.0070.01116.87
7.3.130.0060.01516.90
7.3.120.0060.01516.90
7.3.110.0070.01017.00
7.3.100.0100.00716.87
7.3.90.0070.01116.98
7.3.80.0140.00316.87
7.3.70.0150.00616.92
7.3.60.0070.01016.96
7.3.50.0070.01016.97
7.3.40.0120.00316.91
7.3.30.0150.00616.94
7.3.20.0130.00916.85
7.3.10.0070.01516.93
7.3.00.0100.00717.05
7.2.330.0110.00717.18
7.2.320.0000.01817.26
7.2.310.0070.01117.22
7.2.300.0030.01517.24
7.2.290.0120.01217.16
7.2.280.0070.01117.00
7.2.270.0110.01117.16
7.2.260.0130.00617.07
7.2.250.0040.01417.16
7.2.240.0110.00717.18
7.2.230.0080.00817.09
7.2.220.0070.01017.16
7.2.210.0090.00917.13
7.2.200.0100.00717.11
7.2.190.0060.01616.99
7.2.180.0070.01117.12
7.2.170.0090.00917.16
7.2.160.0070.01017.13
7.2.150.0130.01017.14
7.2.140.0070.01117.09
7.2.130.0090.00917.23
7.2.120.0150.00317.24
7.2.110.0000.01717.18
7.2.100.0180.00017.34
7.2.90.0030.01517.10
7.2.80.0160.00917.08
7.2.70.0140.01117.31
7.2.60.0100.01317.21
7.2.50.0140.00917.04
7.2.40.0090.00917.25
7.2.30.0150.01217.13
7.2.20.0070.01717.07
7.2.10.0000.01817.16
7.2.00.0110.00717.27

preferences:
35.06 ms | 403 KiB | 5 Q