3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $permalink = 'permalink'; $text_link = 'text_link'; $links = array( '<li><a>total</a></li>', '<li><a href="permalink">permalink</a></li>', '<li><a href="permalink">permalink</a></li>', ); $total = count($links); for($permalink=1; $permalink<=$total ;$permalink++){ $links[] = preg_replace('|<a>'.$total.'</a>|', '<a>'.$text_link.'</a>', $links[$permalink]); } print_r($links);
Output for 4.3.0 - 7.1.0
Array ( [0] => <li><a>total</a></li> [1] => <li><a href="permalink">permalink</a></li> [2] => <li><a href="permalink">permalink</a></li> [3] => <li><a href="permalink">permalink</a></li> [4] => <li><a href="permalink">permalink</a></li> [5] => <li><a href="permalink">permalink</a></li> )