3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $permalink = 'permalink'; $text_link = 'text_link'; $links = array( '<li><a href="permalink">permalink1</a></li>', '<li><a href="permalink">permalink2</a></li>', '<li><a href="permalink">permalink3</a></li>', ); $total = count($links); foreach($links as $link){ $new_links[] = preg_replace('|<a[^>]*>'.$total.'</a>|', '<a>'.$text_link.'</a>', $link); } print_r($new_links);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => <li><a href="permalink">permalink1</a></li> [1] => <li><a href="permalink">permalink2</a></li> [2] => <li><a href="permalink">permalink3</a></li> )