Forum Moderators: coopster

Message Too Old, No Replies

How to add anchors on the fly

         

Leto2

4:10 am on Aug 1, 2007 (gmt 0)

10+ Year Member



I've seen lots of webpages with certain words that are automatically linked to something. Usually it will be a word like "blog" or something that will bring up an add when you roll over it.

On an HTML/PHP/maybe MySQL site, is there a way to search for certain strings and replace them with a link to a different page? I would like to do this on all the pages on the site, perhaps by adding a function.

For example, if my site was about widgets, then every time the word blue appeared, anywhere in the site, I'd like blue to be linked to the blue widget page. So you can click on "blue" and be taken there. If "red" appeared somewhere in the text, I'd like to have a link to the red widget page.

Thanks in advance for any help.

eelixduppy

6:43 am on Aug 1, 2007 (gmt 0)



str_replace [php.net] is probably your best bet here. Create an array of all the searches and the replacements and run the function on the string.