Forum Moderators: coopster
$words = array(
'Google' => 'http://www.google.com',
'Yahoo' => 'http://www.yahoo.com'
);
$exp = array();
$rplc = array();
foreach ($words as $word => $url)
{
$exp[] = '/ ' . preg_quote($word) . ' /i';
$rplc[] = ' <argh href="' . $url . '">' . $word . '</argh> ';
}
$this->post['message'] = preg_replace($exp, $rplc, $this->post['message']);
$this->post['message'] = preg_replace_callback("#(<a [^>]*>)((?:[^<]|<(?!/?a>)|(?R))+)(</a>)#", create_function('$a', 'return $a[1] . preg_replace("#<argh[^>]*>(.*?)</argh>#", "$1", $a[2]) . $a[3];'), $this->post['message']);
$this->post['message'] = preg_replace(array('#<argh #', '#</argh>#'), array('<a ', '</a>'), $this->post['message']);