discuss methods for replacing text with relevant links
Hello everybody... I'm about to add a feature to my web site, but I was hoping to get some feedback about what method I should use to do it (or if I should do it at all).
I'm trying to make my site as user friendly as possible by replacing words displayed in posts with links to the relevant site (ie: Microsoft would turn into a link to Microsoft's main site).
1) Is this something that would be useful, or would readers just find it an intrusion?
2) What method should I use? I can only really think of one that would be fairly fast, but then again, I'm not the best programmer. I was thinking of using two arrays, one containing the text and one containing the link... Then using a strreplace to replace them. The problem occurs when somebody has already entered a link. I don't want to replace the text if it's within a link or already linked to...
Preg functions would give you much more control over textual patterns. Look up PCRE (Perl Compatible Regular Expressions) in php.net and get ready to do some reading if you don't know about it.
As for this being an efficient way to deal with this problem, I doubt it. I don't see it being very scalable (imagine having a replacement list of 100+ terms/company names/buzz words). Running 100+ preg_replace functions for 100+ terms would slow down your script. If you just want to stick with very few, this should do fine.
I hate regular expressions . I've seen those companies that offer advertisement that works kind of like what I want... Or is that a browser plugin? Know how that works?
Bookmarks