Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 19th, 2006, 02:45 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,993 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 16 h 39 m 38 sec
Reputation Power: 1557
Post Vbscript - automatic parsing of links inside text

use the code below to parse links that are inside text.
it contains example of usage as well, for any questions
or problems post here.

Code:
<% Option Explicit %>
<%
Function AddLinks(strText)
	Dim result, arrWords, x
	Dim curWord, blnLinkActive
	result=""
	arrWords=Split(strText, " ")
	blnLinkActive = False
	For x=0 TO UBound(arrWords)
		curWord=arrWords(x)
		If LCase(curWord)="<a" Then
			blnLinkActive = True
		End If
		If LCase(curWord)="</a>" Then
			blnLinkActive = False
		End If
		If Not(blnLinkActive) Then
			If IsURL(curWord) Then
				curWord="<a href=""" & MakeFullURL(curWord) & """>" & curWord & "</a>"
			End If
		End If
		result = result & curWord
		If x<UBound(arrWords) Then result=result&" "

	Next
	Erase arrWords
	AddLinks=result
End Function

Function IsURL(strText)
	Dim arrTmp
	IsURL=True
	If BeginsWith(strText, "http://") Then Exit Function
	If BeginsWith(strText, "https://") Then Exit Function
	arrTmp=Split(strText, ".")
	If UBound(arrTmp)>1 Then
		If FindInArray(arrTmp, " ")=0 Then
			If IsValidDomain( arrTmp(UBound(arrTmp)) ) Then
				Erase arrTmp
				Exit Function
			End If
		End If
	End If
	Erase arrTmp
	IsURL=False
End Function

Function MakeFullURL(strText)
	Dim result
	If (Not(BeginsWith(strText, "http://"))) And (Not(BeginsWith(strText, "https://"))) Then
		result = "http://"
	End If
	result = result & strText
	MakeFullURL = result
End Function

Function BeginsWith(strBig, strSmall)
	BeginsWith = (Left(LCase(strBig), Len(strSmall))=LCase(strSmall))
End Function

Function FindInArray(arr, strToFind)
	Dim x, result
	result=0
	For x=0 To UBound(arr)
		If InStr(1, arr(x), strToFind, 1)>0 Then result=result+1
	Next
	FindInArray=result
End Function

Function IsValidDomain(str)
	'optional.... if you want, have list of all available domains and compare.
	IsValidDomain=True
End Function

Dim strText
strText="hello please go to http://www.google.com and visit us again at ynet.co.il"
Response.Write(AddLinks(strText))
%>

Reply With Quote
  #2  
Old December 19th, 2006, 08:06 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
Here is a Regular Expression version.

(Not fully tested)

asp Code:
Original - asp Code
  1. <%
  2. Function parseURL(strText)
  3.   Set regEx = New RegExp
  4.   regEx.Global = true
  5.   regEx.IgnoreCase = True
  6.   regEx.Pattern = "(\b(ht|f)tp(s?)://[^ ]+\b)"
  7.   parseURL = regEx.Replace(strText,"<a href=""$1"">$1</a>")
  8. End Function
  9.  
  10. Dim strings(4)
  11. strings(0) = "Hello there, please visit http://www.google.com to search for things"
  12. strings(1) = "https://domain.com is a secure address"
  13. strings(2) = "An FTP site will be in the format of ftp://domain.com"
  14. strings(3) = "It could also have a username; ftp://user@ftp.domain.com"
  15. strings(4) = "http://www.domain.co.uk/folder/page.ext?var=val"
  16.  
  17. For Each str In strings
  18.     Response.Write parseURL(str) & "<br>"
  19. Next
  20. %>
__________________
CyberTechHelp

Reply With Quote
  #3  
Old December 19th, 2006, 08:35 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,993 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 16 h 39 m 38 sec
Reputation Power: 1557
what about such string?
Code:
strings(0) = "Hello there, please visit <a href=""http://www.google.com"">http://www.google.com</a> to search for things"

Reply With Quote
  #4  
Old December 20th, 2006, 06:36 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
The script I posted is to parse links from plain text. e.g. If you just typed http://google.com in to the reply box.

It could probably be changed to add support for HTML code, the same as your script could be changed to handle ftp:// addresses and attributes e.g. <a href="google.com" id="link1">google.com</a>

Reply With Quote
  #5  
Old December 20th, 2006, 06:39 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,993 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342508 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 16 h 39 m 38 sec
Reputation Power: 1557
attributes are "supported" - my script will ignore anything between
"<a" and "</a>" and leave it as-is. as for ftp:// you're correct,
adding this is very easy though.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Vbscript - automatic parsing of links inside text


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway