filter html-tags, but not all...

Ask a Question related to ASP, Design and Development.

  1. #1

    Default filter html-tags, but not all...

    Hello

    I was wondering if you guys could help me. im building a small messageboard
    and i want to filter all html-tags except these ones:

    <b> <i> <img.........> <font....>

    how to build such a reg exp pattern?

    TIA
    /Lasse


    Lasse Edsvik Guest

  2. Similar Questions and Discussions

    1. Using HTML tags in Flash
      Hello I have some XML that's loaded into Flash by ActionScript and in the XML, I have some text under a node as a parameter called "content" but...
    2. html character enities and other html tags in Contribute3.x
      If you need support/integration of additional html character entities and other html tags in Contribute 3.x, please let Macromedia know that you are...
    3. InDesign CS - HTML Export Filter
      Product name: InDesign Version: CS Operating system: Windows How to export to HTML format ? The plug-in "HTML export Filter" doesn't exist...
    4. search in html tags
      hi friends i am not prof programmer but, in my program i save content by editor online and when i want to search content i have this problem : ...
    5. How to use HTML::Parser to remove HTML tags and print result
      I am trying to use HTML::Parser to parse an HTML file, remove all HTML tags (including comments, etc.), replace all ENTITIES (e.g. &amp), and put...
  3. #2

    Default Re: filter html-tags, but not all...

    I ~guess~ this non-regular expression may work:


    sPost = Request.Form("TheTextArea")
    sPost = Replace(sPost, "<", "&lt;")
    sPost = Replace(sPost, "&lt;b>", "<b>")
    sPost = Replace(sPost, "&lt;/b>", "</b>")
    sPost = Replace(sPost, "&lt;i>", "<i>")
    sPost = Replace(sPost, "&lt;/i>", "</i>")
    sPost = Replace(sPost, "&lt;img", "<img")
    sPost = Replace(sPost, "&lt;font", "<font")
    sPost = Replace(sPost, "&lt;/font>", "</font>")


    If I got that right, it'll replace all the <'s with &lt;'s, and then go back
    and re-replace the <b, <i, <img, <font and they're closing equivalents.
    This will still leave > everywhere, but that shouldn't matter. I'm sure
    there is a more robust solution out there, anyway.

    Ray at work

    "Lasse Edsvik" <lasse@nospam.com> wrote in message
    news:OKaELmInDHA.2216@TK2MSFTNGP12.phx.gbl...
    > Hello
    >
    > I was wondering if you guys could help me. im building a small
    messageboard
    > and i want to filter all html-tags except these ones:
    >
    > <b> <i> <img.........> <font....>
    >
    > how to build such a reg exp pattern?
    >
    > TIA
    > /Lasse
    >
    >

    Ray at Guest

  4. #3

    Default Re: filter html-tags, but not all...

    hmm, i was hoping for a reg.exp solution

    /Lasse


    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:uz42k8JnDHA.3700@TK2MSFTNGP11.phx.gbl...
    > I ~guess~ this non-regular expression may work:
    >
    >
    > sPost = Request.Form("TheTextArea")
    > sPost = Replace(sPost, "<", "&lt;")
    > sPost = Replace(sPost, "&lt;b>", "<b>")
    > sPost = Replace(sPost, "&lt;/b>", "</b>")
    > sPost = Replace(sPost, "&lt;i>", "<i>")
    > sPost = Replace(sPost, "&lt;/i>", "</i>")
    > sPost = Replace(sPost, "&lt;img", "<img")
    > sPost = Replace(sPost, "&lt;font", "<font")
    > sPost = Replace(sPost, "&lt;/font>", "</font>")
    >
    >
    > If I got that right, it'll replace all the <'s with &lt;'s, and then go
    back
    > and re-replace the <b, <i, <img, <font and they're closing equivalents.
    > This will still leave > everywhere, but that shouldn't matter. I'm sure
    > there is a more robust solution out there, anyway.
    >
    > Ray at work
    >
    > "Lasse Edsvik" <lasse@nospam.com> wrote in message
    > news:OKaELmInDHA.2216@TK2MSFTNGP12.phx.gbl...
    > > Hello
    > >
    > > I was wondering if you guys could help me. im building a small
    > messageboard
    > > and i want to filter all html-tags except these ones:
    > >
    > > <b> <i> <img.........> <font....>
    > >
    > > how to build such a reg exp pattern?
    > >
    > > TIA
    > > /Lasse
    > >
    > >
    >
    >

    Lasse Edsvik Guest

  5. #4

    Default Re: filter html-tags, but not all...

    Lasse Edsvik wrote:
    > hmm, i was hoping for a reg.exp solution
    >
    Patience. Chris (Hohmann) usually doesn't start posting this early in the
    day. ;-)

    If you're really impatient, you may want to Google this group for some of
    Chris' RegExp posts that may help you figure it out for yourself...

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

  6. #5

    Default Re: filter html-tags, but not all...

    Lasse Edsvik wrote on 27 okt 2003 in
    microsoft.public.inetserver.asp.general:
    > I was wondering if you guys could help me. im building a small
    > messageboard and i want to filter all html-tags except these ones:
    >
    > <b> <i> <img.........> <font....>
    >
    > how to build such a reg exp pattern?
    This answer is in [serverside-asp ;-)] Jscript
    and supposes you also want to keep </b>, </i>, etc.


    // replace the < of those 8 with ##&##
    t = t.replace(/<{1}?(?=\/?(b|i|img|font)( |>))/g,"##&##")

    // replace all other tags with a space
    t = t.replace(/<[^>]+>/g," ")

    // replace all ##&## back to <
    t = t.replace(/##&##/g,"<")

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

    // all in one single line:
    t = t.replace(/<{1}?(?=\/?(b|i|img|font)( |>))/g,"##&##").replace(/<[^>]
    +>/g," ").replace(/##&##/g,"<")





    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139