striping HTML tags from string, but leaving paragraph formatting

K

Kevin Blount

I have a string of HTML (used for a specific purpose) that I'd like to
use somewhere else but as plain text. Rather than introduce a
specifically created plain text version I'd like to strip the tags code
from the HTML version. This in itself is easy, using a function such
as:

Function HTMLDecode(Expression)
Dim sTemp
sTemp = Expression
sTemp = Replace(sTemp, ">", ">", , , 1)
sTemp = Replace(sTemp, "&lt;", "<", , , 1)
'Repeat for each defined entity
HTMLDecode = sTemp
End Function

However, the difficulty comes when trying keep each paragraph seperate.
For example, the string "this is<p>my name" shows on screen as:

this is

my name

if I use the above function, it strips out the <p> tag and shows the
result on one line:

this is my name

I thought I could use something like:

str = replace(str, "<p>", chr(10))

but that doesn't seem to work. Can anyone help me replace <br> and <p>
tags with something that's recognised as "plain" text but will keep the
paragraphs and new lines formatted correctly??
 
E

Evertjan.

Kevin Blount wrote on 06 dec 2005 in
microsoft.public.inetserver.asp.general:
Function HTMLDecode(Expression)
Dim sTemp
sTemp = Expression
sTemp = Replace(sTemp, "&gt;", ">", , , 1)

This is not necessary, if all the < are gone.
sTemp = Replace(sTemp, "&lt;", "<", , , 1)

this is enough
'Repeat for each defined entity
???

HTMLDecode = sTemp
End Function

However, the difficulty comes when trying keep each paragraph seperate.
For example, the string "this is<p>my name" shows on screen as:

this is

my name

if I use the above function, it strips out the <p> tag and shows the
result on one line:

this is my name

I don't think so, it will be: "this is&lt;p>my name"

rendered by the browser to show:

this is<p>my name

============================

I would define your function in ASP-jscript:

<% = HTMLDecode("this is<p>my name") %>

<script language=jscript runat=server>
function HTMLDecode(Expression) {
return Expression.replace(/</g,'&lt;')
}
</script>
 
K

Kevin Blount

Thanks for the response. That function didn't do what I was looking
for, but I was able to figure it out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top