| Home | Convert URLs into Hyperlinks | KV's Kool ASP | |||||||||||||||||||||||||
|
Convert URLs into Hyperlinks - Source Code I have written the conversion logic as a function, so that I can call it in any of my ASP pages. fnConvertIntoURL.asp is the ASP page that contains the conversion function. Source of fnConvertIntoURL.asp page: <% startPos = 1 WHILE startPos < LEN(inputStr) posURL = InStr(startPos, LCASE(inputStr), "http://") IF posURL = 1 THEN
outputStr = outputStr & _ ELSE
outputStr = outputStr & _
outputStr = outputStr & " <a href="""
IF posURLEnd < 1 THEN urlStr = MID(inputStr, posURL, posURLEnd - posURL) IF LEFT(LCASE(urlStr), 7) <> "http://" THEN linkStr = "http://" & urlStr ELSE linkStr = urlStr END IF
outputStr = outputStr & linkStr & """>" ELSE
outputStr = outputStr & MID(inputStr, startPos) END IF WEND convertIntoURL = outputStr END FUNCTION %> To call this function from any ASP page, add the following line on top of your ASP page: <!--#include file="fnConvertIntoURL.asp"--> where "fnConvertIntoURL.asp" is the ASP page that contains the above conversion function. And to convert URL strings into Hyperlinks in any given string, just pass the string to "convertIntoURL" as below: newString = convertIntoURL(myString) Hope this code will be useful for you in many applications. Click here to see this code working! |
||||||||||||||||||||||||||
| Refer this site | ASPAlliance.com | Contact Us | Join | Advertise | Best Viewed with IE 4.0 or above | ||||||||||||||||||||||||||