This may even be possible without callbacks, I think.
Something along these lines
preg_replace('/\b'.implode('|', $glossary_terms).'\b/i', '<a href="glossary.php?term=$0">$0</a>', $content);
Just make sure your terms do not contain any characters that would be treated as special.
Using a backreference in the replacement argument also gets you around possible issues with losing capitalization of the link text, but then again might raise problems with capitalization in the link itself, so your glossary script would need to be prepared to process the terms no matter how they are capitalized.