Generally, you want to do this sort of link-searching as infrequently as possible, because there's no particularly efficient way to do it. You didn't specify what sort of data your site has on it, but I'm going to assume it's something like a wiki, or a blog. I'm going to talk about this sort of functionality as it would be done for a wiki, but a similar approach would work for anything.
With a wiki, you only want to be doing the link-searching when a page is changed (or submitted in the first place). Note that there are two different ways that links have to be processed. First, when a page is created or edited, you need to search that page's text to determine what links should be in it. Second, whenever any page is created, renamed, or deleted, you need to (in addition to the search of this page in the case of creation) search all other pages to add/update/remove links as needed. There are a few options for how to store these links.
One option is to keep two "versions" of every page's text in the database. One version is the original "markup" version, this is what you actually entered, and what will be displayed if you choose to edit the page. The second version is the parsed/processed "display" version. This is the data that is used to display the page to normal viewers.
For example, if your wiki markup for bold is **
, the "markup version" has **bold text**
, and the "display version" has <strong>bold text</strong>
. This makes it so that you don't have to process your markup on every page view.
This approach is applied to page-links by doing a search through the submitted text to find words that should be linked, and putting those links into the "display version". For example, when a page is submitted, you would step through every word in the page's text and compare it against a list of "link words" (make sure you have this list cached, you don't want to be doing a database query for every word). This can be made fairly efficient by storing the potential linkwords as keys into a hash. If the word being tested is in the "link word" list, you put a link to the relevant page around the word when you copy it into the "display version" text. If it's not, you just put the word in, exactly as it was in the "markup version".
There are a few other options about how to implement this, but that's a fairly straightforward one. I'll leave you with that for now, but if you'd like to me to describe any of the other options, let me know in a comment and I'll edit it in.