473,396 Members | 1,997 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.

removin html tags from string - but leaving a few behind

hi

i have seen several examples (blogs in particular)

http://www.lastkissed.com/?p=7#comments

where placing html into a textarea seems to be stripped out on the other
side. and yet retains some...

for example the above - i placed a </table> into the comment and submitted -
the <blockquote> came out as a block quote but the </table> seems to have
dissappeared.

is there a way i can do a similar box - ie so that if someone puts html into
it - it is stripped out?

thanks for help

Diablo
Jul 22 '05 #1
20 1466
diablo wrote on 01 jul 2005 in microsoft.public.inetserver.asp.general:
i have seen several examples (blogs in particular)

http://www.lastkissed.com/?p=7#comments

where placing html into a textarea seems to be stripped out on the
other side. and yet retains some...

for example the above - i placed a </table> into the comment and
submitted - the <blockquote> came out as a block quote but the
</table> seems to have dissappeared.

is there a way i can do a similar box - ie so that if someone puts
html into it - it is stripped out?


In ASP Jscript:

<%
myString = myString.replace(/<[^>]*>/g,'');
%>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #2
How would you leave out, say, <img and <a tags, so you could allow
hyperlinks and img references but nothing else?
In ASP Jscript:

<%
myString = myString.replace(/<[^>]*>/g,'');
%>

Jul 22 '05 #3
Foo Man Chew wrote on 01 jul 2005 in
microsoft.public.inetserver.asp.general:
In ASP Jscript:

<%
myString = myString.replace(/<[^>]*>/g,'');
%>

[please do not toppost on usenet]
How would you leave out, say, <img and <a tags, so you could allow
hyperlinks and img references but nothing else?


I would think:

myString = myString.replace(/<img /ig,'%%%img ');
myString = myString.replace(/<a /ig,'%%%a ');
myString = myString.replace(/<\/a>/ig,'%%%/a>');
myString = myString.replace(/<[^>]*>/g,'');

myString = myString.replace(/%%%/g,'<');

NOT TESTED!

However this would not keep an end-of-line <a, <img.
Inline '%%%' strings need to be prevented.
But, as this is not a pais helpline, I leave that to your expertise.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #4
> [please do not toppost on usenet]

Please don't tell me how to post, you come off sounding like a
self-appointed net nanny.
Jul 22 '05 #5
Foo Man Chew wrote on 01 jul 2005 in
microsoft.public.inetserver.asp.general:
[please do not toppost on usenet]


Please don't tell me how to post, you come off sounding like a
self-appointed net nanny.


First I was not "telling" you, but asking you.
There is no need to insult someone informing you
to the content of netiquette.
Netiquette is not a joke,
but an important part of usenet for decades.

I am glad you followed my advice though.

===========

How are you getting on with the regex code lines?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #6

How are you getting on with the regex code lines?

I found this

http://weblogs.asp.net/rosherove/arc...963.aspx#84206

but what i am wanting is the reverse of it - ie i want to say:

remove all html except for <blockquote> <em> <strong> <a>

whereas i think the above (link) removes the listed tags.

OK - i know that catering for all cases (ie missing end tags and spaces etc)
is difficult and long winded - but surely there is a simple way to do this.

Thanks again

Diablo

Jul 22 '05 #7
"diablo" <di****@noplace.com> wrote in message
news:Xe****************@newsfe5-gui.ntli.net...

How are you getting on with the regex code lines?

I found this

http://weblogs.asp.net/rosherove/arc...963.aspx#84206

but what i am wanting is the reverse of it - ie i want to say:

remove all html except for <blockquote> <em> <strong> <a>

whereas i think the above (link) removes the listed tags.

OK - i know that catering for all cases (ie missing end tags and spaces
etc)
is difficult and long winded - but surely there is a simple way to do
this.


Use negative lookahead matching:

myString = myString.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
Jul 22 '05 #8
> Netiquette is not a joke,
but an important part of usenet for decades.

I am glad you followed my advice though.


I was merely demonstrating that in some cases either form is acceptable. I
know of no all-ruling governing body that states that one must use only one
form or the other. You like bottom-posting; good for you. That does not
mean that I have to change my posting habits to make you happy.

Jul 22 '05 #9
Use negative lookahead matching:

myString = myString.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");


I am sorry - my reg ex is virtually nill

can you please provide a ASP scripty examlple

really appreciated

Diablo

Jul 22 '05 #10
diablo wrote on 02 jul 2005 in microsoft.public.inetserver.asp.general:
Use negative lookahead matching:

myString =

myString.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");


I am sorry - my reg ex is virtually nill

can you please provide a ASP scripty examlple


<%
function myReplace(s){
return
s.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
};
%>

using ASP Jscript
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #11
ya, what is up with you and your non stop top posting comments.
Just keep it to yourself..

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.242...
Foo Man Chew wrote on 01 jul 2005 in
microsoft.public.inetserver.asp.general:
[please do not toppost on usenet]


Please don't tell me how to post, you come off sounding like a
self-appointed net nanny.


First I was not "telling" you, but asking you.
There is no need to insult someone informing you
to the content of netiquette.
Netiquette is not a joke,
but an important part of usenet for decades.

I am glad you followed my advice though.

===========

How are you getting on with the regex code lines?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #12
PJones wrote on 02 jul 2005 in microsoft.public.inetserver.asp.general:
ya, what is up with you and your non stop top posting comments.
Just keep it to yourself..


Certainly not.

The only way usenet remains such a usefull commodity is netiquette.

Correct posting belongs to netiquette, Mr Jones.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #13

"Foo Man Chew" <fo*@man.chew> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
:> Netiquette is not a joke,
: > but an important part of usenet for decades.
: >
: > I am glad you followed my advice though.
:
: I was merely demonstrating that in some cases either form is acceptable.

Laziness is only acceptable in Liberal environments. Show me any written
material that reads, scroll down, down, down, read down, scroll up, read
down, scroll up, read down, scroll up, read down.

I understand your philosophy, I just don't agree with it. "Help me with my
issue to make it easier for me but don't expect me to adhere to any standard
that makes it easier for you to help me. It's all about me."

Noted!

: I
: know of no all-ruling governing body that states that one must use only
one
: form or the other.

So, that's two noted things you don't know. Looks like a trend.

: You like bottom-posting; good for you. That does not
: mean that I have to change my posting habits to make you happy.

It's not bottom posting. It's related to a conversation. Yours is related
to nothing more than laziness. Either follow the standard and make it
easier for those helping you to make your life easier or soon you'll be
doing it on your own. Biting the hand that feeds you will cause you to
reach that goal sooner.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #14
"PJones" <pj****@hotmail.com> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
: ya, what is up with you and your non stop top posting comments.
: Just keep it to yourself..

So, only you get to state your opinion? Let's review:

Evertjan made a pleasant request, which makes it easier for everyone and
still chose to satisfy the request.
Foo Man Chew asked for help and then whined and chose to ignore Evertjan's
request for help while catching an attitude.
You entered the conversation only to make a demand, offering no help
whatsoever.

Is it really too much to ask to follow a standard which makes the thread
easier to follow, especially when you're asking for help? Trim the text not
needed. It saves bandwidth and respond to the previous post as you would in
a conversation. Do you provide an answer before the question is asked? No,
that would be stupid.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #15

<%
function myReplace(s){
return
s.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
};
%>

using ASP Jscript

Any chance of a VBscript translation please - thanks - for all the help

Diablo
Jul 22 '05 #16
diablo wrote on 03 jul 2005 in microsoft.public.inetserver.asp.general:
<%
function myReplace(s){
return
s.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
};
%>

using ASP Jscript

Any chance of a VBscript translation please - thanks - for all the help


These pages show both the replace syntax for Jscript and vbscript:

http://msdn.microsoft.com/library/en...mthreplace.asp

http://msdn.microsoft.com/library/en...mthReplace.asp
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #17
> Do you provide an answer before the question is asked?
Alex Trebek does :>).

Bob Lehmann

"Roland Hall" <nobody@nowhere> wrote in message
news:uG**************@TK2MSFTNGP10.phx.gbl...
"PJones" <pj****@hotmail.com> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
: ya, what is up with you and your non stop top posting comments.
: Just keep it to yourself..

So, only you get to state your opinion? Let's review:

Evertjan made a pleasant request, which makes it easier for everyone and
still chose to satisfy the request.
Foo Man Chew asked for help and then whined and chose to ignore Evertjan's
request for help while catching an attitude.
You entered the conversation only to make a demand, offering no help
whatsoever.

Is it really too much to ask to follow a standard which makes the thread
easier to follow, especially when you're asking for help? Trim the text not needed. It saves bandwidth and respond to the previous post as you would in a conversation. Do you provide an answer before the question is asked? No, that would be stupid.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp MSDN Library - http://msdn.microsoft.com/library/default.asp

Jul 22 '05 #18

"Roland Hall" <nobody@nowhere> wrote in message
news:uG**************@TK2MSFTNGP10.phx.gbl...
"PJones" <pj****@hotmail.com> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
: ya, what is up with you and your non stop top posting comments.
: Just keep it to yourself..

So, only you get to state your opinion? Let's review:

Evertjan made a pleasant request, which makes it easier for everyone and
still chose to satisfy the request.
Foo Man Chew asked for help and then whined and chose to ignore Evertjan's
request for help while catching an attitude.
You entered the conversation only to make a demand, offering no help
whatsoever.

Is it really too much to ask to follow a standard which makes the thread
easier to follow, especially when you're asking for help? Trim the text not needed. It saves bandwidth and respond to the previous post as you would in a conversation. Do you provide an answer before the question is asked? No, that would be stupid.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp MSDN Library - http://msdn.microsoft.com/library/default.asp


Oops! I meant...Do you provide an answer before the question is asked?

Alex Trebek does :>).

Bob Lehmann

Jul 22 '05 #19
"Bob Lehmann" wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
:> Do you provide an answer before the question is asked?
: Alex Trebek does :>).

hehehe

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #20
"Bob Lehmann" wrote in message news:uw**************@tk2msftngp13.phx.gbl...
:
: Oops! I meant...
: >Do you provide an answer before the question is asked?
: Alex Trebek does :>).

Alex is on my list. (O;=

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #21

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

Similar topics

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...
72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
32
by: Cornel Bicutzi | last post by:
Hello, What is the difference between HTML and XHTML... Thanks, ------------------------------------------------------------------------ IT Interview Questions :...
1
by: unklevo | last post by:
Is there an easy way to convert HTML that comes from database as a string into text and display it on winform... Thanks.
2
by: Kevin Blount | last post by:
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...
9
by: anupamjain | last post by:
Hi, After 2 weeks of search/hit-and-trial I finally thought to revert to the group to find solution to my problem.(something I should have done much earlier) This is the deal : On a JSP...
3
by: jobs at webdos | last post by:
I have a bunch of html pages and a database table with links to them. I want to dynamically display those pages inside a set location on an exsisting asp.net 2.0 page when a link is selected,...
6
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Is there a function in VS or a utility that will take an HTML file and create a code-behind ASPX page? The idea is, I'd like to be able to have someone develop beautiful, fully functional HTML...
1
by: since | last post by:
I figured I would post my solution to the following. Resizable column tables. Search and replace values in a table. (IE only) Scrollable tables. Sortable tables. It is based on a lot...
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
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.