SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict jkassemi's Avatar
    Join Date
    Jan 2005
    Location
    Albuquerque
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    Any ideas? Appreciate it,

    James

  2. #2
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    New York
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Addict jkassemi's Avatar
    Join Date
    Jan 2005
    Location
    Albuquerque
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

    Thanks,
    James.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •