• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

Remove SPAN Tag

The code below is being read from a database. I want to  remove the span tags before it is displayed on the screen, i however want to keep all other tags such as <p>

<SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-GB; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><p>the road<p/></SPAN>

Im using the following code:

txt = your span content
txt = Right(txt,Len(txt) - Instr(txt,">")) ' positon of first occurance of ">" 
txt = Left(txt,Instr(txt,("</SPAN"))-1)  
Response.Write(txt)

But keep gettin the error: Invalid procedure call or argument 'Left'

can somebody please tell me a way to fix this problem

Thanks Kevin
0
KeKiteley
Asked:
KeKiteley
  • 2
  • 2
1 Solution
 
SlimshaneeyCommented:
This might work, not tested, have a try though.

Function clearTags(HTML)
Dim re
Set re = New RegExp
re.Pattern = "(<[?]SPAN[^>]*>)"
re.Global = True
clearTags = re.Replace(HTML, "")
End Function
0
 
SlimshaneeyCommented:
Also, you could try this, I modified it from another answer....

Function ReplaceFont(ByVal strFormatArea)
    'create variables
    Dim objRegEx
    dim strMatchPattern
     'create instance of RegExp object
    Set objRegEx = New RegExp

     '** FIND ALL MATCHES **
    objRegEx.Global = True
    ' ** SET CASE SENSITIVE **
    objRegEx.IgnoreCase = True

    ' ** GET THE SPANTAG **
     '** looks for a string starting with <SPAN, followed by anything except a closing bracket, followed by a closing bracket **
    strMatchPattern = "<span[^>]+>"
    ' ** SET PATTERN **
    objRegEx.Pattern = strMatchPattern    
     ' ** REMOVE SPAN START TAG **
    strFormatArea = objRegEx.Replace(strFormatArea, "")

     ' ** GET THE SPAN END TAG **
    strMatchPattern = "</span>"
    ' ** SET PATTERN **
    objRegEx.Pattern = strMatchPattern
    ' ** REMOVE THE SPAN END TAG **
    strFormatArea = objRegEx.Replace(strFormatArea, "")
     

    ' Return the result
    ReplaceFont = strFormatArea
    Set objRegEx=nothing
End Function
0
 
HilaireCommented:
Please try this shorter version

Function RemoveSPanTags(str)
dim obj
set obj = createobject("vbscript.regexp")
with obj
   .global = true
   .pattern = "\<SPAN[^>]*>(.*)</SPAN>"
   str= .replace(str, "$1")
end with
set obj = nothing
end Function
0
 
HilaireCommented:
Oops typo

Function RemoveSPanTags(str)
dim obj
set obj = createobject("vbscript.regexp")
with obj
   .global = true
   .pattern = "\<SPAN[^>]*>(.*)</SPAN>"
   RemoveSPanTags= .replace(str, "$1")
end with
set obj = nothing
end Function

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now