Foros del Web » Programando para Internet » ASP Clásico »

limpiador de html en asp

Estas en el tema de limpiador de html en asp en el foro de ASP Clásico en Foros del Web. hola he encontrado este limpiador de tags html en asp Código PHP: 'De esta manera se hace la llamada a la funcion para quitar el HTML (siempre tras declarar la función) strPlainText = RemoveHTML(strTextWithHTML)  ' Esta es la funci & #243;n  Function  RemoveHTML (  strText  )       Dim TAGLIST  ...
  #1 (permalink)  
Antiguo 09/12/2009, 17:04
Avatar de engonga
Usuario no validado
 
Fecha de Ingreso: marzo-2002
Ubicación: Buenos Aires
Mensajes: 1.300
Antigüedad: 23 años, 1 mes
Puntos: 8
limpiador de html en asp

hola he encontrado este limpiador de tags html en asp

Código PHP:
'De esta manera se hace la llamada a la funcion para quitar el HTML (siempre tras declarar la función)
strPlainText = RemoveHTML(strTextWithHTML) 


'
Esta es la función 
Function RemoveHTMLstrText 
    
Dim TAGLIST 
     
'Todas las etiquetas que se encuentren en esta lista serán removidas de 
la cadena de texto 
     '
Es importante recordar que todas las etiquetas deben estar rodeqadas 
de 
; (punto y coma
    
TAGLIST ";!--;!DOCTYPE;A;ACRONYM;ADDRESS;APPLET;AREA;B;BASE;BASEFONT;" 
&
              
"BGSOUND;BIG;BLOCKQUOTE;BODY;BR;BUTTON;CAPTION;CENTER;CITE;CODE;" 
&
              
"COL;COLGROUP;COMMENT;DD;DEL;DFN;DIR;DIV;DL;DT;EM;EMBED;FIELDSET;" 
&
              
"FONT;FORM;FRAME;FRAMESET;HEAD;H1;H2;H3;H4;H5;H6;HR;HTML;I;IFRAME;IMG;" 
&
              
"INPUT;INS;ISINDEX;KBD;LABEL;LAYER;LAGEND;LI;LINK;LISTING;MAP;MARQUEE;" 
&
              
"MENU;META;NOBR;NOFRAMES;NOSCRIPT;OBJECT;OL;OPTION;P;PARAM;PLAINTEXT;" 
&
              
"PRE;Q;S;SAMP;SCRIPT;SELECT;SMALL;SPAN;STRIKE;STRONG;STYLE;SUB;SUP;" 
&
              
"TABLE;TBODY;TD;TEXTAREA;TFOOT;TH;THEAD;TITLE;TR;TT;U;UL;VAR;WBR;XMP;" 


     'Todas las etiquetas que se encuentren en esta lista serán removidas 
desde la etiqueta de inicio hasta la de cierre 
     '
por ejemplo una llamada a un objeto de flash que abre asi <OBJECT..... 
sera removida hasta donde termine el </OBJECT..... 
    Const 
BLOCKTAGLIST 
";APPLET;EMBED;FRAMESET;HEAD;NOFRAMES;NOSCRIPT;OBJECT;SCRIPT;STYLE;" 


    
Dim nPos1 
    Dim nPos2 
    Dim nPos3 
    Dim strResult 
    Dim strTagName 
    Dim bRemove 
    Dim bSearchForBlock 


    nPos1 
InStr(strText"<"
    Do While 
nPos1 
        nPos2 
InStr(nPos1 1strText">"
        If 
nPos2 0 Then 
            strTagName 
Mid(strTextnPos1 1nPos2 nPos1 1
     
strTagName Replace(Replace(strTagNamevbCr" "), vbLf" "


            
nPos3 InStr(strTagName" "
            If 
nPos3 0 Then 
                strTagName 
Left(strTagNamenPos3 1
            
End If 


            If 
Left(strTagName1) = "/" Then 
                strTagName 
Mid(strTagName2
                
bSearchForBlock False 
            
Else 
                
bSearchForBlock True 
            End 
If 


            If 
InStr(1TAGLIST";" strTagName ";"vbTextCompare) > 
Then 
                bRemove 
True 
                
If bSearchForBlock Then 
                    
If InStr(1BLOCKTAGLIST";" strTagName ";"
vbTextCompare) > 0 Then 
                        nPos2 
Len(strText
                        
nPos3 InStr(nPos1 1strText"</" strTagName
vbTextCompare
                        If 
nPos3 0 Then 
                            nPos3 
InStr(nPos3 1strText">"
                        
End If 


                        If 
nPos3 0 Then 
                            nPos2 
nPos3 
                        End 
If 
                    
End If 
                
End If 
            Else 
                
bRemove False 
            End 
If 


            If 
bRemove Then 
                strResult 
strResult Left(strTextnPos1 1
                
strText Mid(strTextnPos2 1
            Else 
                
strResult strResult Left(strTextnPos1
                
strText Mid(strTextnPos1 1
            
End If 
        Else 
            
strResult strResult strText 
            strText 
"" 
        
End If 


        
nPos1 InStr(strText"<"
    
Loop 
    strResult 
strResult strText 


    RemoveHTML 
strResult 
End 
Function 
http://www.webtrucos.com/programacio...quitartags.txt


pero cuando lo uso me da un error de sintaxis

Código:
Error de compilación de Microsoft VBScript (0x800A03EA)
Error de sintaxis
/cda/noticies.asp, línea 391
Function RemoveHTML( strText ) 
alguien sabe por que?

Última edición por engonga; 09/12/2009 a las 17:05 Razón: añadir
  #2 (permalink)  
Antiguo 10/12/2009, 05:17
Avatar de Valery-Net  
Fecha de Ingreso: agosto-2008
Mensajes: 694
Antigüedad: 16 años, 8 meses
Puntos: 12
Respuesta: limpiador de html en asp

qué código tienes en la línea 391?
  #3 (permalink)  
Antiguo 10/12/2009, 05:39
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 18 años, 4 meses
Puntos: 126
Respuesta: limpiador de html en asp

Hola

Por darte otra alternativa. Yo prefiero usar expresiones regulares

Código asp:
Ver original
  1. <%
  2. Function LimpiarTags(cadena)
  3. Dim objRegExp
  4. cadena = lcase(cadena)
  5. cadena = Replace(cadena,"'", """")
  6. cadena = Replace(cadena,"", "")
  7. cadena = Trim(cadena & "")
  8. If Len(cadena) > 0 Then
  9.  
  10.     Set objRegExp= New RegExp
  11. objRegExp.IgnoreCase = True
  12. objRegExp.Global = True
  13. objRegExp.Pattern = "<[^>]+>" 'todos los tags HTML
  14. 'objRegExp.Pattern = "<img[^<>]+>" 'imagenes
  15. strlimpio = objRegExp.Replace(cadena, " ")
  16.     Set objRegExp = Nothing
  17. End If
  18.     LimpiarTags = strlimpio
  19. End Function
  20.  
  21. Dim cadalimpiar
  22. cadalimpiar = "<table border='1'><tr><td>hola</td></tr></table><div>adios</div><img src='javier.gif' />"
  23. %>
  24.  
  25. <%=LimpiarTags(cadalimpiar)%>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #4 (permalink)  
Antiguo 10/12/2009, 05:57
Avatar de engonga
Usuario no validado
 
Fecha de Ingreso: marzo-2002
Ubicación: Buenos Aires
Mensajes: 1.300
Antigüedad: 23 años, 1 mes
Puntos: 8
Respuesta: limpiador de html en asp

ya esta solucionado he puesto la funcion al final de todo el codigo y ya funciona

es un limpiados muy bueno y parametrizable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:30.