- str_replace: documentation ( source)
- preg_replace: documentation ( source)
<?php
$txt = 'hello world<br />#helloworld<br />some more text';
$txt = str_replace('<br />','<br />',$txt);
$txt = preg_replace('/(?<!\w)#([0-9a-zA-Z]+)/m', '<a href="index.php?q=$1">#$1</a>', $txt);
echo $txt;