3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div> Some text <img src="https://example.com/foo?bar=food"> and a raw link http://example.com/number2 then <a href="https://example.com/the/third/url">original text</a> ... and <p>here's another HTTPS://www.example.net/booyah</p> and done </div> HTML; $dom = new DOMDocument(); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); $regex = '#\bhttps?://[-\w.]+(?::\d+)?(?:/(?:[\w/_.-]*(?:\?\S+)?)?)?#ui'; foreach ($xpath->query('//*[not(self::a)]/text()') as $textNode) { $text = $textNode->nodeValue; foreach (preg_match_all($regex, $text, $m) ? $m[0] : [] as $url) { $a = $dom->createElement('a', htmlspecialchars($url)); $a->setAttribute('href', $url); $mbPosOfUrlInText = mb_strpos($text, $url); // regurgitate any leading text as newpreceding node // then replace remainder of text with new hyperlink $textNode->parentNode->replaceChild( $a, $textNode->splitText($mbPosOfUrlInText) ); // add any text after url as new text node after new hyperlink $textNode->parentNode->insertBefore( $dom->createTextNode( mb_substr($text, $mbPosOfUrlInText + mb_strlen($url)) ), $a->nextSibling ); } } echo $dom->saveHTML();

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.5.30.0120.00619.73
8.5.20.0120.00820.41
8.5.10.0120.00617.07
8.5.00.0140.00720.41
8.4.180.0130.01022.41
8.4.170.0080.01422.38
8.4.160.0170.01122.46
8.4.150.0080.00517.21
8.4.140.0110.01118.33
8.4.130.0100.00818.46
8.4.120.0130.00420.88
8.4.110.0090.01222.91
8.4.100.0130.00918.29
8.4.90.0120.00918.92
8.4.80.0130.00818.59
8.4.70.0150.00518.47
8.4.60.0070.01419.29
8.4.50.0140.00718.55
8.4.40.0090.00018.28
8.4.30.0070.01119.32
8.4.20.0100.01020.14
8.4.10.0080.00020.02
8.3.300.0090.00721.20
8.3.290.0140.00721.33
8.3.280.0100.01020.77
8.3.270.0110.00917.09
8.3.260.0110.00917.31
8.3.250.0100.01019.06
8.3.240.0100.01117.32
8.3.230.0090.00317.41
8.3.220.0100.00717.49
8.3.210.0080.01017.46
8.3.200.0060.00217.30
8.3.190.0150.00517.50
8.3.180.0070.01417.18
8.3.170.0130.00721.00
8.3.160.0100.00617.09
8.3.150.0070.01317.84
8.3.140.0120.00317.06
8.3.130.0080.00019.07
8.3.120.0090.00319.51
8.3.110.0060.00320.94
8.3.100.0040.00717.11
8.3.90.0080.00026.77
8.3.80.0420.00730.84
8.3.70.0350.01430.84
8.3.60.0450.00330.84
8.3.50.0100.01030.84
8.3.40.0250.00930.84
8.3.30.0300.00930.84
8.3.20.0270.01230.84
8.3.10.0390.00030.84
8.3.00.0250.01030.84
8.2.300.0110.01020.66
8.2.290.0140.00621.17
8.2.280.0130.00620.62
8.2.270.0120.00617.79
8.2.260.0070.01119.13
8.2.250.0000.00917.22
8.2.240.0100.00017.67
8.2.230.0030.00522.58
8.2.220.0030.00624.06
8.2.210.0000.00826.77
8.2.200.0260.00730.84
8.2.190.0320.00630.84
8.2.180.0170.00330.84
8.2.170.0240.00730.84
8.2.160.0250.00430.84
8.2.150.0410.01530.84
8.2.140.0370.00330.84
8.2.130.0180.00630.84
8.2.120.0170.00630.84
8.2.110.0190.00030.84
8.2.100.0190.00330.84
8.2.90.0160.00530.84
8.2.80.0210.00630.84
8.2.70.0310.01230.84
8.2.60.0350.00830.84
8.2.50.0340.00830.84
8.2.40.0380.00430.84
8.2.30.0420.00830.84
8.2.20.0210.01030.84
8.2.10.0230.00730.84
8.2.00.0100.01030.84
8.1.340.0110.01020.96
8.1.330.0130.00722.62
8.1.320.0130.00716.71
8.1.310.0070.00316.88
8.1.300.0110.00016.69
8.1.290.0130.00830.84
8.1.280.0140.00530.84
8.1.270.0130.00730.84
8.1.260.0250.01330.84
8.1.250.0190.00830.84
8.1.240.0220.00730.84
8.1.230.0230.01430.84
8.1.220.0390.00030.84
8.1.210.0330.00930.84
8.1.200.0270.01230.84
8.1.190.0420.00430.84
8.1.180.0310.01230.84
8.1.170.0280.01030.84
8.1.160.0290.00630.84
8.1.150.0210.01030.84
8.1.140.0280.01030.84
8.1.130.0320.00630.84
8.1.120.0340.00630.84
8.1.110.0400.00730.84
8.1.100.0350.00830.84
8.1.90.0260.01030.84
8.1.80.0310.00730.84
8.1.70.0380.00030.84
8.1.60.0300.01230.84
8.1.50.0280.01430.84
8.1.40.0270.01030.84
8.1.30.0370.00630.84
8.1.20.0290.01330.84
8.1.10.0360.00730.84
8.1.00.0310.01130.84

preferences:
37.6 ms | 1029 KiB | 5 Q