echo str_replace("example","<a href='http://example.com'>example</a>","Wood example forest.");
Możesz też użyć wyrażeń regularnych.
https://stackoverflow.com/questions/17245317/parse-text-for-hashtags-and-replace-with-links-using-php
http://www.regular-expressions.info/
$text = "Vivamus #tristique non elit eu iaculis.";
$text = preg_replace('/#(\w+)/', ' <a href="tag/$1">$1</a>', $text);
echo preg_replace("@(?<!\S)#([0-9a-zA-Z]+)@","<a href='http://example.com'>$1</a>","#hash #tag #tag #hash");
Edit:
Chyba o taki kod Ci chodziło:
<style>
a{
text-decoration:none;
}
</style>
<?php
$text = "Vivamus #tristique non #traszka #Pójdźmy_idźmy elit eu iaculis";
$patterns = array();
$patterns[0] = "@#([0-9A-Za-ząćęłńóśźżĄĆĘŁŃÓŚŹŻ_\-]+\w)@";
$patterns[1] = "@(elit)@";
$replacements = array();
$replacements[0] = "<a href=\"http://example.com\"><span style=\"background:lightgrey\">$1</span></a>";
$replacements[1] = "<a href=\"http://example.com\"><span style=\"background:lightgreen\">$1</span></a>";
$text = preg_replace($patterns,$replacements, $text);
echo $text;
?>