3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $s = '<li id="item" class="list-item" href="#">Item</li><li id="item" class="list-item" href="#">Item</li>'; $find = "li"; $lenght = strlen($find); $pos1 = strpos($s, $find); $pos2 = strrpos($s, $find); //Echo substr($s,0,$pos1) . "a" . Substr($s,$pos1+$lenght,$pos2-$lenght-1) . "a" . Substr($s,$pos2+$lenght); Echo str_replace(array("<li ", "</li>"), array("<a ", "</a>"), $s);
based on EdaM4
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
<a id="item" class="list-item" href="#">Item</a><a id="item" class="list-item" href="#">Item</a>