3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML 税务调查。 [caption id="attachment_111" align="aligncenter" width="100"]<img src="https://royaldesign.com/image/11/gubi-moon-dining-table-round-120-h73-3?w=168&quality=80" alt="拜登与儿子。" width="100" height="100" class="size-full wp-image" /> 拜登与儿子。[/caption] 他在声明中说:“我会非常认真地调查,往来。” <img src="https://royaldesign.com/image/11/gubi-moon-dining-table-round-120-h73-3?w=168&quality=80" alt="拜登总统" width="100" height="100" class="aligncenter size-full wp-image" /> <div style="position:relative; overflow:hidden"> <iframe src="https://cdn.google.com/players/VM.html" width="100" height="100" frameborder="0" scrolling="auto" title="大促销 拜登的美国" style="position:absolute;"></iframe> </div> <iframe style="border: none; overflow: hidden;" src="https://www.facebook.com/plugins/video.php?height=100&amp;href=https%3A%2F%2Fwww.facebook.com;width=100&amp;t=0" width="100" height="100" frameborder="0" allowfullscreen="allowfullscreen"></iframe> <iframe src="https://www.facebook.com/plugins/video.php?height=400&href=https%3A%2F%2&show_text=false&width=100&t=0" width="100" height="100" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowfullscreen="true" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share" allowFullScreen="true"></iframe> <b>更多热点</b> <p>halo拜登也指美国经济不会衰退</p> <figure id="attachment_279" style="width: 100px" class="wp-caption alignnone"><img class="size-full wp-imag" src="https://royaldesign.com/image/11/gubi-moon-dining-table-round-120-h73-3?w=168&quality=80" alt="修理厂商总会拜登城" width="100" height="100" /><figcaption class="wp-caption-text">修理厂商总会拜登城</figcaption></figure> <a href="http://google.com">go to google</a> <span style="color: #ff6600;"><strong>另外,拜登声明中说</strong></span> HTML; $dom = new DOMDocument; libxml_use_internal_errors(true); $dom->preserveWhiteSpace = true; $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED ); $xpath = new DOMXPath($dom); $tags = ["拜登", "认真"]; $orContains = '(' . implode( ' or ', array_map( fn($str) => "contains(text(), '$str')", $tags ) ) . ')'; $blacklisted = implode( ' or ', array_map( fn($tag) => "descendant-or-self::$tag", ['a', 'img', 'iframe', 'figure', 'figcaption'] ) ); $path = "//*[not($blacklisted) and $orContains]"; //echo $path . "\n\n\n---\n"; foreach ($xpath->query($path) as $node) { $newText = preg_replace( '~\[caption .+?\[/caption](*SKIP)(*FAIL)|' . implode('|', $tags) . '~us', '<span class="article-tag"><a class="mytag" href="http://outside.com">$0</a></span>', $dom->saveXML($node), -1, $count ); if ($count) { $replacement = $dom->createDocumentFragment(); $replacement->appendXML($newText); $node->parentNode->replaceChild($replacement, $node); } } foreach ($xpath->query("/p/text()") as $node) { var_export($dom->saveXML($node)); echo "\n====\n"; /*$newText = preg_replace( '~(?:\[caption .+?\[/caption]|<span class="article-tag"><a class="mytag" href="http://outside.com">.*?</a></span>)(*SKIP)(*FAIL)|' . implode('|', $tags) . '~us', '<span class="article-tag"><a class="mytag" href="http://outside.com">$0</a></span>', $dom->saveXML($node), -1, $count ); if ($count) { $replacement = $dom->createDocumentFragment(); $replacement->appendXML($newText); $node->parentNode->replaceChild($replacement, $node); } */ } echo html_entity_decode(mb_substr($dom->saveXML($dom->documentElement), 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.3.70.0140.00717.75
8.3.60.0040.01819.08
8.3.50.0130.01020.89
8.3.40.0140.00722.40
8.3.30.0090.00919.55
8.3.20.0040.00424.23
8.3.10.0030.00524.66
8.3.00.0090.00026.16
8.2.190.0160.00017.38
8.2.180.0130.01025.92
8.2.170.0140.00719.83
8.2.160.0090.00622.96
8.2.150.0050.00325.66
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0000.00920.28
8.2.110.0070.00319.91
8.2.100.0060.00618.50
8.2.90.0030.00619.84
8.2.80.0000.00818.38
8.2.70.0070.00318.38
8.2.60.0000.00918.55
8.2.50.0070.00318.25
8.2.40.0030.00620.21
8.2.30.0040.00418.80
8.2.20.0040.00422.81
8.2.10.0040.00418.78
8.2.00.0030.00519.79
8.1.280.0110.01425.92
8.1.270.0090.00024.34
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0060.00319.91
8.1.230.0090.00319.60
8.1.220.0040.00418.28
8.1.210.0100.00018.77
8.1.200.0060.00617.98
8.1.190.0030.00617.98
8.1.180.0060.00318.10
8.1.170.0080.00019.36
8.1.160.0030.00519.43
8.1.150.0040.00419.46
8.1.140.0080.00018.27
8.1.130.0030.00619.51
8.1.120.0000.00818.15
8.1.110.0040.00418.13
8.1.100.0040.00418.23
8.1.90.0040.00418.03
8.1.80.0120.00718.18
8.1.70.0120.00718.07
8.1.60.0200.00218.32
8.1.50.0060.00618.11
8.1.40.0040.00818.31
8.1.30.0140.00018.31
8.1.20.0060.00618.41
8.1.10.0040.00918.14
8.1.00.0040.01118.20
8.0.300.0090.00018.77
8.0.290.0080.00017.50
8.0.280.0040.00419.07
8.0.270.0040.00417.63
8.0.260.0040.00418.95
8.0.250.0000.00717.82
8.0.240.0030.00517.66
8.0.230.0080.00317.84
8.0.220.0080.00017.76
8.0.210.0050.00917.66
8.0.200.0130.00517.58
8.0.190.0150.00317.60
8.0.180.0180.00017.72
8.0.170.0120.00617.69
8.0.160.0140.00617.69
8.0.150.0070.01217.61
8.0.140.0140.00417.54
8.0.130.0100.00717.68
8.0.120.0000.01917.72
8.0.110.0140.00617.58
8.0.100.0060.01017.57
8.0.90.0050.01117.69
8.0.80.0060.01217.59
8.0.70.0150.00317.47
8.0.60.0150.00417.74
8.0.50.0100.00717.66
8.0.30.0140.00317.59
8.0.20.0100.00717.75
8.0.10.0150.00317.50
7.4.330.0000.00615.55
7.4.320.0080.00017.30
7.4.300.0160.00317.29
7.4.290.0130.00517.23
7.4.280.0140.00517.36
7.4.270.0060.01217.17
7.4.260.0130.00417.32
7.4.250.0100.01017.38
7.4.240.0130.00417.38
7.4.230.0130.00517.41
7.4.220.0170.00017.36
7.4.210.0120.00417.17
7.4.200.0140.00217.45
7.4.190.0130.00317.37
7.4.180.0030.00917.43
7.4.160.0130.00017.39
7.4.150.0060.00617.35
7.4.140.0100.00517.02
7.4.130.0080.00617.05
7.4.120.0070.00717.07
7.4.110.0070.00717.15
7.4.100.0070.00716.76
7.4.90.0110.00017.26
7.4.80.0080.00617.10
7.4.70.0040.00817.27
7.4.60.0040.00817.37
7.4.50.0140.00017.33
7.4.40.0120.00017.13
7.4.30.0060.00617.40
7.4.20.0080.00317.19
7.4.10.0090.00017.15
7.4.00.0050.00517.15

preferences:
52.03 ms | 401 KiB | 5 Q