parse link?? not sure... please help..

Discussion in 'PHP' started by LOD, Oct 30, 2009.

  1. #1
    hi guys
    i am making a comment section on my site... and i want my users to be able to provide url link... which will automatically be appearing as a link... suppose if the users write anything with "http://" it will be acted as a link...
    now how can i do that??
    thanks in advance...
     
    LOD, Oct 30, 2009 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    function parse_links($text)
    {
        return preg_replace('~(?:ht|f)tps?://[^\s\(\)"\'<>\!]+~i', '<a href="$0">$0</a>', $text);
    }
    
    PHP:
    ... untested, but should work.
     
    nico_swd, Oct 30, 2009 IP
    LOD likes this.
  3. LOD

    LOD Member

    Messages:
    319
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #3
    i dont understand what u wrote... :S
     
    LOD, Oct 30, 2009 IP
  4. org

    org Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    that's an regular expression, they are a lil hard to read but they work really good.
    You might google and look at some tutorials then you will soon know how to use regular expressions.
     
    org, Oct 30, 2009 IP
  5. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #5
    I always thought that regular expression is a combination of smiley faces.
    but only after I learned how to use it I finally understood how amazing it is.
     
    astrazone, Oct 30, 2009 IP
  6. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Tested, and it does work. Nice regex. :)
     
    organicCyborg, Oct 31, 2009 IP
  7. LOD

    LOD Member

    Messages:
    319
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #7
    thanks guys.... that works as u said...
     
    LOD, Nov 5, 2009 IP