Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,256
Total Threads: 81,169
Total Posts: 566,839
There are 32 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     .NET and MSSQL :

Stripping HTML from an ASP code and then Trimming It

Thread title: Stripping HTML from an ASP code and then Trimming It
Reply    
    Thread tools Search this thread Display Modes  
09-20-2010, 03:27 PM
#1
jimmykup is offline jimmykup
Status: I'm new around here
Join date: Apr 2010
Location:
Expertise:
Software:
 
Posts: 11
iTrader: 0 / 0%
 

jimmykup is on a distinguished road

  Old  Stripping HTML from an ASP code and then Trimming It

Hello,

To start off I would like to say that I have very little experience in dealing with classic ASP. My specialty is HTML and CSS so I'm a little bit lost here. Hopefully someone here can lend me a hand.

My Goal:
My company sells projectors and other AV equipment. I would like to take the product descriptions that appear on the individual product pages and use them in my META tags and Facebook OpenGraph tags.

The Problem:
The product descriptions are saved in our database as text with HTML tags in it. I need these descriptions to load into my HTML as plain text without HTML elements or styling.

Here's what I would like to do:
1. Strip HTML tags from a body of text.
2. Trim that text to a pre-determined length or after a certain amount of sentences.

Here is the ASP tag in my HTML that loads the product description. And here is an example of one of the pages it loads into.

Code:
<%=sDescription%>
I searched for a code that would help me with removing the HTML tags and I found this piece right here.

Code:
Function stripTags(HTMLstring)
    Set RegularExpressionObject = New RegExp
    With RegularExpressionObject
        .Pattern = "<[^>]+>"
        .IgnoreCase = True
        .Global = True
    End With
    stripTags = RegularExpressionObject.Replace(HTMLstring, "")
    Set RegularExpressionObject = nothing
End Function
But I don't know how to get that code to interact with my code. I'm familiar with Regular Expressions so I understand how this code does what it does. Unfortunately I don't understand anything else about it. I've tried replacing "HTMLstring" with my code but that didn't do anything.

If this code isn't enough, there's plenty of more code in my source that I can supply you with. Just tell me what I should be looking for. Any help would be greatly appreciated, thank you!

Reply With Quote
09-20-2010, 04:40 PM
#2
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Just run the code though Server.HTMLEncode()

Reply With Quote
09-20-2010, 06:25 PM
#3
jimmykup is offline jimmykup
Status: I'm new around here
Join date: Apr 2010
Location:
Expertise:
Software:
 
Posts: 11
iTrader: 0 / 0%
 

jimmykup is on a distinguished road

  Old

I looked up Server.HTMLEncode() on this site. It seems as if this code will only turn the HTML tags into their plain text equivalent.

What I want to do is remove the HTML characters entirely, not just convert them to plain text.

Reply With Quote
09-22-2010, 03:44 PM
#4
jimmykup is offline jimmykup
Status: I'm new around here
Join date: Apr 2010
Location:
Expertise:
Software:
 
Posts: 11
iTrader: 0 / 0%
 

jimmykup is on a distinguished road

  Old

I was able to figure this out using this code.

Code:
<%End if
	If Not rsItems.Eof Then
		sDescription = rsItems("WEBDESC")
		If Not rsParent.Eof Then%>

<%Function stripHTML(strHTML) 
	Dim objRegExp, strOutput
	Set objRegExp = New Regexp
	objRegExp.IgnoreCase = True
	objRegExp.Global = True
	objRegExp.Pattern = "<(.|\n)+?>"
	strOutput = objRegExp.Replace(strHTML, "")
	strOutput = Replace(strOutput, "<", "&lt;")
	strOutput = Replace(strOutput, ">", "&gt;")
	stripHTML = strOutput 'Return the value of strOutput
	Set objRegExp = Nothing
End Function%> 

<%=stripHTML(sDescription)%>

<%End if%>

Reply With Quote
Reply    


Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed