- Code : Tout sélectionner
Function HTMLTagRemove(wChaine As String, wnbRemoveBreakRow As Boolean, wnbRemoveJavaScript As Boolean,wnbRemoveCSS As Boolean) As String
Dim Chaine As String
Dim vrValue As Variant
Dim Texte As String
Dim tbRemove(0 To 1)
On Error Goto ErreurHandle
HTMLTagRemove = ""
If Trim(wChaine) = "" Then
HTMLTagRemove = wChaine
Exit Function
End If
If Instr(wChaine,"<") = 0 Then
HTMLTagRemove = wChaine
Exit Function
End If
Chaine = wChaine
'retire les retour chariot
If wnbRemoveBreakRow = True Then
tbRemove(0) = Chr(10)
tbRemove(1) = Chr(13)
Chaine = Replace(Chaine,tbRemove,"")
Erase tbRemove
End If
'retire les balise Js et le javascript contenu
If wnbRemoveJavaScript = True Then
If Instr(Lcase(Chaine),"<script") > 0 Then
vrValue = Split(Chaine,"<script",,2)
If Isempty(vrValue) = False Then
If Isarray(vrValue) = True Then
Chaine = ""
Forall value In vrValue
Texte = Trim(Cstr(value))
If Texte <> "" Then
If Instr(Lcase(Texte),"script>") > 0 Then
Chaine= Chaine+Strrightback(Texte,"script>",1)
Else
Chaine= Chaine+Texte
End If
End If
End Forall
End If
End If
End If
vrValue = Null
End If
'retire les balise style et tout le style contenu
If wnbRemoveCSS= True Then
If Instr(Lcase(Chaine),"<style") > 0 Then
vrValue = Split(Chaine,"<style",,2)
If Isempty(vrValue) = False Then
If Isarray(vrValue) = True Then
Chaine = ""
Forall value In vrValue
Texte = Trim(Cstr(value))
If Texte <> "" Then
If Instr(Lcase(Texte),"style>") > 0 Then
Chaine= Chaine+Strrightback(Texte,"style>",1)
Else
Chaine= Chaine+Texte
End If
End If
End Forall
End If
End If
End If
vrValue = Null
End If
'retire toute les balise restante
vrValue = Split(Chaine,"<")
If Isempty(vrValue) = False Then
If Isarray(vrValue) = True Then
Chaine = ""
Forall value In vrValue
Texte = Trim(Cstr(value))
If Texte <> "" Then
If Instr(Texte,">") > 0 Then
Chaine= Chaine+Strright(Texte,">")
Else
Chaine = Chaine+Texte
End If
End If
End Forall
End If
End If
vrValue = Null
HTMLTagRemove = Chaine
Chaine = ""
Exit Function
ErreurHandle:
Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
HTMLTagRemove = ""
Exit Function
End Function