Ver Mensaje Individual
  #27 (permalink)  
Antiguo 29/10/2004, 10:54
Avatar de AlZuwaga
AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 23 años, 2 meses
Puntos: 535
Crea enlaces en textos.
Acepta targets y estilos personalizados.
Los enlaces deben comenzar por http, es decir que no acepta direcciones del tipo www.loquesea.com ni ventas.loquesea.com



Código:
<%
Function CrearEnlaces(varTexto, strTarget, strClass)
	arrTexto = Split(varTexto, " ")
	
	For i = 0 To UBound(arrTexto)
		UltimoCaracter = Right(arrTexto(i), 1)
			If UltimoCaracter = "." Then arrTexto(i) = Left(arrTexto(i), Len(arrTexto(i)) - 1) & " " & UltimoCaracter
			If UltimoCaracter = "," Then arrTexto(i) = Left(arrTexto(i), Len(arrTexto(i)) - 1) & " " & UltimoCaracter
			If UltimoCaracter = ";" Then arrTexto(i) = Left(arrTexto(i), Len(arrTexto(i)) - 1) & " " & UltimoCaracter
		varTextoArreglado = Join(arrTexto)
	Next
	
	arrTexto2 = Split(varTextoArreglado, " ")
	
	For i = 0 To UBound(arrTexto2)
		HTTP = Left(LCase(arrTexto2(i)), 4)
			If HTTP = "http" Then
				URL = "<a href=""" & arrTexto2(i) & """ target=""" & strTarget & """ class=""" & strClass & """>" & arrTexto2(i) & "</a>"
				arrTexto2(i) = URL
			End if
		varTextoArreglado2 = Join(arrTexto2)
	Next
	varTextoArreglado2 = Replace(varTextoArreglado2, " . ", ". ")
	varTextoArreglado2 = Replace(varTextoArreglado2, " , ", ", ")
	varTextoArreglado2 = Replace(varTextoArreglado2, " ; ", "; ")
	CrearEnlaces = varTextoArreglado2
End Function
%>

Demo:
Código:
<%
Texto = "La siguiente es una dirección que tiene un punto al final (aunque podría haber tenido una coma u otro sígno de puntuación): http://www.forosdelweb.com/. Esta otra no http://www.google.com pero tiene un espacio y no tiene barra. Esta última no tiene nada al final, porque está al final del string y además tiene parámetros: http://www.google.com/search?hl=en&q=%22Club+Atl%C3%A9tico+Boca+Juniors%22"
Response.Write Texto
Response.Write "<br>"
Response.Write "<br>"
Response.Write CrearEnlaces(Texto, "_blank", "enlaces")
%>

Salud
PD: 100% mejorable
__________________
...___...