When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs



















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Software Developer / Programmer - Interview NOW!
Next Step Systems
US-IL-Des Plaines

Justtechjobs.com Post A Job | Post A Resume

Published: Friday, October 01, 1999

Stripping HTML Tags
By Abd Shomad


Note from Scott Mitchell, webmaster:
Ah, it's nice to see an article by Abd. It's been too long since his last article! This nifty little script will strip all the HTML tags from out of a string.


Here's a way to Strip HTML Tags. I found this snippet of code is very usefull when you want to output either HTML or PLAIN TEXT with your ASPMail/CDONTS component. (To learn more about sending emails through an ASP page, be sure to read the Email FAQ Category section at ASPFAQs.com!)

- continued -

Here's the code:

' Function Strip All HTML Tags ' Author Abd Shomad: ' http://www.4guysfromrolla.com/webtech/abdshomad.shtml Function StripHTMLTag(ByVal sText) StripHTMLTag = "" fFound = False Do While InStr(sText, "<") fFound = True StripHTMLTag = StripHTMLTag & " " & Left(sText, InStr(sText, "<")-1) sText = MID(sText, InStr(sText, ">") + 1) Loop StripHTMLTag = StripHTMLTag & sText If Not fFound Then StripHTMLTag = sText End Function

For this to work, your HTML tags must be VALID HTML tags! If you have any < or >, that do not denote the beginning of an HTML tag, you need to repalce < with &lt; and > with &gt; (for example, if you have in your HTML string: "The following is a true statement: 5 < 10", you would need to replace the < with &lt;.)

A More Updated Version
The above function is a bit buggy and picky, requiring a matching number of < and > signs. A cleaner and more flexible HTML stripping function can be found at: Stripping HTML Tags Using Regular Expressions.

Happy Programming!


Attachments:

  • The source code for the StripHTMLTag in text format


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article

  • internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers