SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RegEx For Valid HTTP:// and FTP:// URL's

    Does anyone have a regEx for these?

  2. #2
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends, are you trying to find them in text, or just see if they are valid?
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  3. #3
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I'm checking if it's valid.. I just need the regEx format.

    (ie.
    PHP Code:
    ^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$ 
    )

  4. #4
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, would it be something like...

    ([http://|ftp://])([-_./a-zA-Z0-9!&%#?+,\'=:~]+])

    So I could do something like this...
    PHP Code:
    $text eregi_replace('([http://|ftp://])([-_./a-zA-Z0-9!&%#?+,\'=:~]+]+)','<a href="\\1\\2" target="_blank">\\1\\2</a>'$text); 

  5. #5
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    slight optimization maybe...

    replace

    ([http://|ftp://])

    with

    ([ht|f]tp://)

    Not that it matters that much, but the second one's faster...
    Work smarter, not harder. -Scrooge McDuck

  6. #6
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, so if I use that along with the actual example above using eregi_replace, would that work to find something like http://www.msn.com in a paragraph of text and convert it to a URL?


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
  •