3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "#test Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus #tristique non elit eu iaculis. Vivamus eget ultricies nisi. Vivamus hendrerit at mauris condimentum scelerisque. <a href='http://google.co.uk/#donec'>nibh</a> mauris, pulvinar et #commodo a, porta et tellus. Duis eget ante gravida, convallis augue id, blandit lectus. Mauris euismod commodo mi ut fringilla. Sed felis magna, rhoncus vitae mattis varius, sagittis a eros. Donec eget porta ipsum. <a href='#Mauris'>sed mauris ante</a>. Suspendisse potenti. Donec a #pretium #augue, eget hendrerit orci. Integer cursus scelerisque consequat."; $text = preg_replace('/(?:^|\s)#(\w+)/', ' <a href="tag/$1">$1</a>', $text); echo $text; ?>
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
<a href="tag/test">test</a> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus <a href="tag/tristique">tristique</a> non elit eu iaculis. Vivamus eget ultricies nisi. Vivamus hendrerit at mauris condimentum scelerisque. <a href='http://google.co.uk/#donec'>nibh</a> mauris, pulvinar et <a href="tag/commodo">commodo</a> a, porta et tellus. Duis eget ante gravida, convallis augue id, blandit lectus. Mauris euismod commodo mi ut fringilla. Sed felis magna, rhoncus vitae mattis varius, sagittis a eros. Donec eget porta ipsum. <a href='#Mauris'>sed mauris ante</a>. Suspendisse potenti. Donec a <a href="tag/pretium">pretium</a> <a href="tag/augue">augue</a>, eget hendrerit orci. Integer cursus scelerisque consequat.

preferences:
90.3 ms | 410 KiB | 5 Q