3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keywords = [ 'keywords' => 'www.1.com', 'hello' => 'www.2.com', 'there' => 'www.3.com', 'are' => 'www.4.com', ]; $sentence = ' <div> <h1>Hello</h1> <h2>Hello there blablabla</h2> <p>Hello, there are keywords</p> <p>Hello, there are keywords</p> <p>Hello, there are keywords</p> <p>Hello, there are keywords</p> <p>Hello, there are keywords</p> </div>'; $dom = new DOMDocument; $dom->loadHTML($sentence, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); foreach ($dom->getElementsByTagName('p') as $p) { $p->nodeValue = preg_replace_callback( '~\b(?:' . implode('|', array_keys($keywords)) . ')\b~i', function($m) use ($keywords) { return $keywords[strtolower($m[0])]; }, $p->nodeValue ); } echo $dom->saveHTML();
Output for git.master, git.master_jit, rfc.property-hooks
<div> <h1>Hello</h1> <h2>Hello there blablabla</h2> <p>www.2.com, www.3.com www.4.com www.1.com</p> <p>www.2.com, www.3.com www.4.com www.1.com</p> <p>www.2.com, www.3.com www.4.com www.1.com</p> <p>www.2.com, www.3.com www.4.com www.1.com</p> <p>www.2.com, www.3.com www.4.com www.1.com</p> </div>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
171.07 ms | 406 KiB | 5 Q