Stripping HTML attributes and tags

Discussion in 'HTML' started by JJ Harrison, Nov 27, 2005.

  1. JJ Harrison

    JJ Harrison Guest

    Are there any asp scripts or programs availible that will strip
    selected html tags and remove attributes (such as style info etc)
    automatically availible?
    JJ Harrison, Nov 27, 2005
    #1
    1. Advertising

  2. JJ Harrison

    Spartanicus Guest

    JJ Harrison <> wrote:

    >Are there any asp scripts or programs availible that will strip
    >selected html tags and remove attributes (such as style info etc)
    >automatically availible?


    Any editor that supports Regexps can do that for you.

    --
    Spartanicus
    Spartanicus, Nov 27, 2005
    #2
    1. Advertising

  3. JJ Harrison

    dorayme Guest

    > From: JJ Harrison <>
    >
    > Are there any asp scripts or programs availible that will strip
    > selected html tags and remove attributes (such as style info etc)
    > automatically availible?



    I use BBEdit text editor and the grep pattern search and replace
    function (or indeed often the regular search and replace), will
    work for all files in any selected folder...). Powerful stuff,
    handle with care.

    --
    dorayme
    dorayme, Nov 27, 2005
    #3
  4. JJ Harrison

    JJ Harrison Guest

    On Mon, 28 Nov 2005 09:58:34 +1100, dorayme <>
    wrote:

    >> From: JJ Harrison <>
    >>
    >> Are there any asp scripts or programs availible that will strip
    >> selected html tags and remove attributes (such as style info etc)
    >> automatically availible?

    >
    >
    >I use BBEdit text editor and the grep pattern search and replace
    >function (or indeed often the regular search and replace), will
    >work for all files in any selected folder...). Powerful stuff,
    >handle with care.


    I am not very confident with regular expressions, can anyone suggest a
    good guide or some expressions that would remove all tags except
    <p>,<br>,<ul>,<li>,<b>,<em>,<i>,<strong> and remove all remaining
    attriubtes from the existing tags?

    Thanks
    JJ Harrison, Nov 28, 2005
    #4
  5. JJ Harrison

    Jim Higson Guest

    JJ Harrison wrote:

    > On Mon, 28 Nov 2005 09:58:34 +1100, dorayme <>
    > wrote:
    >
    >>> From: JJ Harrison <>
    >>>
    >>> Are there any asp scripts or programs availible that will strip
    >>> selected html tags and remove attributes (such as style info etc)
    >>> automatically availible?

    >>
    >>
    >>I use BBEdit text editor and the grep pattern search and replace
    >>function (or indeed often the regular search and replace), will
    >>work for all files in any selected folder...). Powerful stuff,
    >>handle with care.

    >
    > I am not very confident with regular expressions, can anyone suggest a
    > good guide or some expressions that would remove all tags except
    > <p>,<br>,<ul>,<li>,<b>,<em>,<i>,<strong> and remove all remaining
    > attriubtes from the existing tags?


    I could, but this is easier:

    http://uk2.php.net/strip_tags

    --
    Jim
    Jim Higson, Nov 28, 2005
    #5
  6. JJ Harrison

    Toby Inkster Guest

    JJ Harrison wrote:

    > I am not very confident with regular expressions, can anyone suggest a
    > good guide or some expressions that would remove all tags except
    > <p>,<br>,<ul>,<li>,<b>,<em>,<i>,<strong> and remove all remaining
    > attriubtes from the existing tags?


    I'll bite...

    #!/usr/bin/perl

    $_ = <<TEST;

    <p class="flibble">
    This is a test. The paragraph should remain,
    but the class should go, as should this
    <u>underline</u>. <little>This should go too,
    and not be reduced to an LI element.</little>
    </p>

    TEST

    s/<\/(p|br|ul|li|b|em|i|strong)>/<\/\1>/ig;
    s/<(p\b|br\b|ul\b|li\b|b\b|em\b|i\b|strong\b)\s*[^>]*>/<\1>/ig;
    s/<\/(?!(p|br|ul|li|b|em|i|strong))[^>]*>/<\/span>/ig;
    s/<(?!(\/|p\b|br\b|ul\b|li\b|b\b|em\b|i\b|strong\b))[^>]*>/<span>/ig;

    print;
    exit;

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Nov 28, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lance
    Replies:
    4
    Views:
    425
    Lance
    Jun 17, 2005
  2. Spondishy

    Stripping html tags from text

    Spondishy, Mar 6, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    4,155
    m.posseth
    Mar 7, 2006
  3. Ken Fine

    Stripping content delimited by two tags

    Ken Fine, Feb 5, 2004, in forum: ASP General
    Replies:
    5
    Views:
    122
    Ray at
    Feb 5, 2004
  4. shank

    stripping HTML tags

    shank, Jul 10, 2004, in forum: ASP General
    Replies:
    3
    Views:
    106
    Alex Kail
    Jul 14, 2004
  5. Jeff North

    Stripping HTML tags from a TEXTAREA field

    Jeff North, Jan 19, 2004, in forum: Javascript
    Replies:
    15
    Views:
    179
Loading...

Share This Page