473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

stripping HTML tags

I'm querying a text field with an 8000 character limit. The text also
contains HTML tags like <p> <br> and more. Is there a way to strip all HTML
tags in the resulting recordset, or do I have to replace each tag
individually?

thanks
Jul 19 '05 #1
3 1869
shank wrote on 10 jul 2004 in microsoft.public.inetserver.asp.general:
I'm querying a text field with an 8000 character limit. The text also
contains HTML tags like <p> <br> and more. Is there a way to strip all
HTML tags in the resulting recordset, or do I have to replace each tag
individually?


Using [serverside] jscript:

YourResult = yourField.replace(/<[^>]*>/g,' ')

Replacing tags with a space, because some tags replace a space in HTML.

This is not perfect.

<input value='a "false" >'>
will give a wrong result
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #2
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.29...
shank wrote on 10 jul 2004 in microsoft.public.inetserver.asp.general:
I'm querying a text field with an 8000 character limit. The text also
contains HTML tags like <p> <br> and more. Is there a way to strip all
HTML tags in the resulting recordset, or do I have to replace each tag
individually?


Using [serverside] jscript:

YourResult = yourField.replace(/<[^>]*>/g,' ')

Replacing tags with a space, because some tags replace a space in HTML.

This is not perfect.

<input value='a "false" >'>
will give a wrong result


Of course the above is not valid HTML, so your code is fine. :)
Jul 19 '05 #3
I've always had great luck with this function:

Function StripHTML(strText)

'Strips the HTML tags from the text passed (strText). AK

'Checking for HTML tag opening brackets
If InStr(1, strText, "<") = 0 Then
'No opening brackets, no chance of HTML being used
'So just return the original string. AK
StripHTML = strText
Exit Function 'Abort
End If

'This takes the potential HTML text passed and
'splits it up into an array to loop through. AK
Dim arySplit, lngLoop, lngStart, strOutput
arySplit = Split(strText, "<")

'Determine where to start parsing
If Len(arySplit(0)) > 0 Then
lngStart = 1 'First character is an opening tag
Else
lngStart = 0
End If

'Taking out the HTML opening tags
For lngLoop = lngStart To UBound(arySplit)
If InStr(arySplit(lngLoop), ">") Then
arySplit(lngLoop) = Mid(arySplit(lngLoop),
InStr(arySplit(lngLoop), ">") + 1)
Else
arySplit(lngLoop) = "<" & arySplit(lngLoop)
End If
Next

strOutput = Join(arySplit, "")
strOutput = Mid(strOutput, 2 - lngStart)
strOutput = Replace(strOutput, ">", ">")
strOutput = Replace(strOutput, "<", "<")

StripHTML = strOutput

End Function
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steveo | last post by:
I am currently stripping HTML from a string with the following code. (I know it's not the best way to strip HTML but bear with me) re.compile("<.*?>") I wanted to allow all H1 and H2 tags so i...
4
by: Michael Vilain | last post by:
Originally, I was using $value =~ s/<.*>//g; to strip HTML tags from a variable. It actually stripped everything from the first "<" to the last ">" after the ending tag. I found this regex...
15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
4
by: Lance | last post by:
Hi, What way could I strip certain tags (like HTML comments) from the HTML being delivered to the client? I don't mean what regexp to use, but where do I put this stripping code? I'm thinking...
4
by: Spondishy | last post by:
Hi, I'm looking for help with a regular expression and c#. I want to remove all tags from a piece of html except the following. <a> <b> <h1> <h2>
6
by: Medros | last post by:
I understand that you can strip html out of a txt file so that all the information is left is the visable information that is needed (e.g. everything that has < > around is gone). My question is...
3
by: Jason | last post by:
First things first, let me say that I couldn't decide whether to post this to the PHP ng, or to an XML ng. I know from experience that you guys know what you're talking about, though, and all of...
2
by: Big Moxy | last post by:
I want to send html formatted text yet strip out special characters (e.g. quotes and semi colons). I've seen preg_replace examples like $messageout = preg_replace('/\(\)<>]/i','',$message); to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.