SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex Clickable URLs

    I'm not one of those few who know regex, so I googled this regex:

    PHP Code:
    $html preg_replace("`((?:https?|ftp)://\S+[[:alnum:]]/?)`si""<a href=\"$1\" target=\"_blank\">$1</a>"$html); 
    I need it so that it only parses urls where there is not a ] or = on the left side, and there is not a [ or ] on the right side of the url. My intention here is that it will not parse urls that are used within bbcode.

    Help would be appreciated!

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:
    $html preg_replace("#(?<!\[|=)((?:https?|ftp)://\S+[[:alnum:]]/?)(?!\])#i""<a href=\"$1\" target=\"_blank\">$1</a>"$html); 
    my mobile portal
    ghiris.ro

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That didn't work, it's still parsing this as a link:

    [img=http://pathtoimage]

    It also needs to ignore < and > on the beginning/end rather than re-write that in the URL, because currently my link reads http://www.google.com<br/> because of the hard return at the end which was converted to BR

    I really appreciate your help

  4. #4
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe this:
    PHP Code:
    (?<!\[url=|\[img=|\[=)((?:https?|ftp)://\S+[[:alnum:]]/?)(?!\]) 
    my mobile portal
    ghiris.ro


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
  •