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?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.