[eluser]sophistry[/eluser]
this might help. i renamed the word_censor function (as it was posted in the linked thread) to regex_mill()
i believe that this demonstrates almost perfectly what you are looking for:
Code:
$s = 'this is a <a href="string">string</a> with text/texts and HTML anchor and img tags (img tag here: <img src="">) mixed in. this is a string without a tag.';
$lookfor = array('(\s)(string)(\s)', 'texts?', 'HTML anchor', '[^<](img)');
$replacements = array('$2<a href="tags/$3">$3</a>$4','<a href="tags/$1">$1</a>','<a href="tags/$1">$1</a>','<a href="tags/$2">$2</a>');
$out = regex_mill($s, $lookfor, $replacements, 'i');
print_r(htmlentities($out));
to understand and use this regex_mill you are going to have to learn some regex to "tune" what the patterns find and what they are replaced with, but this should get you going with the basics.
happy birthday!