Jump to content

Automatically linking 1-3 word phrases in article text


geekinchief

Recommended Posts

I'm writing a PHP script which will take a list of product names from a database (each name is probably 1-3 words in length) and go through the text of a blog post and link any of the names on the list back to a page about that item. Additionally -- and this is key -- I need to make sure it DOES NOT turn the term into a link if it is already inside a link (inside of <a> </a> tags)

 

The data table contains the name of the product (ex: HP Pavilion dv4t or "iPhone") and the URL for the link to it. There will be thousands of product names though very few will be used in any given blog post (maybe 1 to 4) so I don't think it's practical to do a search replace for each them on each post, but I could be wrong. I suppose I could have it compare every 3,2, and 1 word combination in each blog post to each product name.

 

What would you suggest?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.