Print Page | Close Window

removing html tags

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5778
Printed Date: 30 March 2026 at 11:41pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: removing html tags
Posted By: pedalcars
Subject: removing html tags
Date Posted: 16 September 2003 at 7:04am
In this version of the forum, hovering over a topic link will show (using the "title" property of the link) the first (60? 100?) characters of the post body.

If the first section of the post body contains html tags such as a link, these are completely removed before the "title" property is written.

For example, see http://forums.webwiz.net/forum_posts.asp?TID=5777&PN=1&TPN=1 - this test area posting - there's a link very early in the post, but if you go to the http://forums.webwiz.net/forum_topics.asp?FID=15&PN=1 - test forum page , when you hover the link title contains only the plain text, ie, the tags have been removed from the text string.

How is this done?

Ta

-------------
http://www.pedalcars.info/ - www.pedalcars.info

The most fun on four wheels




Replies:
Posted By: Mikael
Date Posted: 16 September 2003 at 12:24pm

Presumably with a filter that strips all the html-tags. Look in functions_filters.asp and see how the tags can be found and stripped out.



Posted By: Mart
Date Posted: 16 September 2003 at 1:46pm
<%=server.htmlEncode("string")%>


Posted By: pedalcars
Date Posted: 16 September 2003 at 2:19pm
Originally posted by Mart Mart wrote:

<%=server.htmlEncode("string")%>


Thanks, but the HTMLEncode function merely encodes what's there, ie:

<a href="link.asp">

becomes

&lt;a href=&quot;link.asp&quot;&gt;

in the HTML of the page, so it renders as text that looks like it should make a link, rather than creating a tag and opening a link.

What I'm after is a method of finding any < and > symbols in the text string and replacing them and everything between any pair of them, such that the entire <a href="link.asp"> section can be taken out, as can any </a>, <p>, </p>, <br />, etc. tags.

If there's a wildcard that can be used in response.replace, that's what I'm after - like

response.replace(strTextString,"<*>","") where * is the wildcard.

As far as I can see, Forum 7.01 doesn't do this but is the latest downloadable version, so I can't check my files!

-------------
http://www.pedalcars.info/ - www.pedalcars.info

The most fun on four wheels



Posted By: MorningZ
Date Posted: 16 September 2003 at 6:34pm

"How can I strip the HTML tags from a text string using regular expressions?"

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=155 - http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=155



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: pedalcars
Date Posted: 17 September 2003 at 3:27am
Perfect, thanks!


-------------
http://www.pedalcars.info/ - www.pedalcars.info

The most fun on four wheels



Posted By: WebWiz-Bruce
Date Posted: 17 September 2003 at 3:56am

Here is what I wrote for the next version of the forum, to strip HTML. It doesn't use regular expersions to keep it compatible with ASP2.0 and pre version 5 of the VB Scripting engine:-

'**********************************************
'***    Strip HTML     *****
'**********************************************

'Remove HTML function
Private Function removeHTML(ByVal strMessageInput)

 Dim lngMessagePosition  'Holds the message position
 Dim intHTMLTagLength  'Holds the length of the HTML tags
 Dim strHTMLMessage  'Holds the HTML message
 Dim strTempMessageInput  'Temp store for the message input


 'Place the message input into a temp store
 strTempMessageInput = strMessageInput

 'Loop through each character in the post message
 For lngMessagePosition = 1 to CLng(Len(strMessageInput))

  'If this is the end of the message then save some process time and jump out the loop
  If Mid(strMessageInput, lngMessagePosition, 1) = "" Then Exit For
  
  'If an HTML tag is found then jump to the end so we can strip it
  If Mid(strMessageInput, lngMessagePosition, 1) = "<" Then

   'Get the length of the HTML tag
   intHTMLTagLength = (InStr(lngMessagePosition, strMessageInput, ">", 1) - lngMessagePosition)
   
   'If the end of the HTML string is in error then set it to the number of characters being passed
   If intHTMLTagLength < 0 Then intHTMLTagLength = CLng(Len(strTempMessageInput))

   'Place the HTML tag back into the temporary message store
   strHTMLMessage = Mid(strMessageInput, lngMessagePosition, intHTMLTagLength + 1)


   'Strip the HTML from the temp message store
   strTempMessageInput = Replace(strTempMessageInput, strHTMLMessage, "", 1, -1, 0)
   
  End If
 Next
 
 'Replace a few characters in the remaining text
 strTempMessageInput = Replace(strTempMessageInput, "'", "&#039;", 1, -1, 1)
 strTempMessageInput = Replace(strTempMessageInput, """", "&#034;", 1, -1, 1)
 strTempMessageInput = Replace(strTempMessageInput, "&nbsp;", "", 1, -1, 1)

 'Return the function
 removeHTML = strTempMessageInput
End Function



-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net