SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    lean mean coding machine cosmo's Avatar
    Join Date
    Aug 2001
    Location
    the cosmos
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parsing URLs in a string

    Hi,

    I am trying to parse URLs within a string, replacing them with an html code to turn it into a link.

    For example, if the following were inserted into a textbox:

    This is an example text. You can learn more by going to:
    http://www.test.com. Also here: http://www.url.com


    The following would be the output:

    This is an example text. You can learn more by going to: <a href="<A href="http://www.test.com/">http://www.test.com">http://www.test.com</a>. Also here: <a href="<A href="http://www.url.com/">http://www.url.com">http://www.url.com</a>.


    Has anyone ever implemented anything like this?

    Thanks.
    Luthfur R. - Web Developer
    PHP Lite.com - Professional PHP Scripts and Web Applications
    Calendar Express 2 - Web Based Calendar and Event Publishing System

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2002
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://aspn.activestate.com/ASPN/Coo...x/Recipe/59864 should be good since it implements the entire RFC 1738 specifications - Have a look at that reg-ex!!
    If that is a *bit* to much for you: http://www.desilva.biz/php/xtracturl.html should get you there.

  3. #3
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check out this post: http://www.sitepointforums.com/showp...32&postcount=3 written by the master of regular expressions

    you would just do
    PHP Code:
    $string make_clickable($string); 
    and it would be there
    - website

  4. #4
    lean mean coding machine cosmo's Avatar
    Join Date
    Aug 2001
    Location
    the cosmos
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for the replies guys.

    Website, that Dr Larry Pepper's code is great! Exactly what I was looking for.

    Nucleuz, thanks for that huge reg-ex! Didn't really need it for my current problem, but I've bookmarked it incase I need it in the future.
    Luthfur R. - Web Developer
    PHP Lite.com - Professional PHP Scripts and Web Applications
    Calendar Express 2 - Web Based Calendar and Event Publishing System


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
  •