2 Replies - 32690 Views - Last Post: 12 October 2010 - 12:10 PM

#1 cyb1n   User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 27
  • Joined: 08-May 09

URL to HTML Hyperlink (RegEx)

Posted 19 July 2010 - 12:48 PM

Description: This code was developed for a simple chat program and is intended to be executed after a FORM submission and prior to being sent to a database/text file. Variable Definitions: RAWMSG - A block of text that may or may not contain a URL (change this as necessary to fit your application). URLREGEX - Returns an array with the position and length of a URL found in MESSAGE (if no URL is present both values are 0). URLSTRING - harvests the URL from MESSAGE using the position and length values of URLREGEX. HYPERLINK - an HTML hyperlink containing the harvested URL contained in URLSTRING. HTMLMSG - The final product, if the original (RAWMSG) contained a URL this will contain an HTML hyperlink which leads to said URL.I was developing a simple chat utility for my site and I wanted a way to easily share links. The snippet simply uses Regular Expressions to determine if a block of plain text contains a URL and replaces the URL with an HTML hyperlink. It's not much, but it is a base which can be built upon.





        
        ' & trim(urlstring) & '' />
        



#htmlmsg#



Is This A Good Question/Topic? 0
  • +

Replies To: URL to HTML Hyperlink (RegEx)

#2 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12566
  • View blog
  • Posts: 45,686
  • Joined: 27-December 08

Re: URL to HTML Hyperlink (RegEx)

Posted 20 September 2010 - 07:14 AM

Snippet only works with properly formed URLs of the format http://myurl.com or https://myurl.com.
Was This Post Helpful? 0
  • +
  • -

#3 cyb1n   User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 27
  • Joined: 08-May 09

Re: URL to HTML Hyperlink (RegEx)

Posted 12 October 2010 - 12:10 PM

That's true, it is very basic and currently only works with properly formed URLs. It was originally designed for quick sharing of links (ie. copying a web page URL from the address bar).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1