#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    Atlanta, GA
    Posts
    10
    Rep Power
    0
    So I need a regular expression to strip out all HTML tags EXCEPT the ones I've allowed.

    I think I almost have it, but I can't get the negation right..

    "/</?(^IMG|A|FONT|B|I|U|STRONG|EM|CODE|PRE|H1|H2|H3|H4|H5|H6)(.*)>?/i"

    Now the ^ isn't negating because it's not in a class. So how would I negate all those tags (meaning match anything EXCEPT those?)

    Also, what's a better alternative to the .* match so that they can't just throw a newline in there and **** things up?
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,640
    Rep Power
    4476
    I'm thinking that what you need is the strip_tags() function....seems a little easier to me....

    strip_tags

    (PHP 3>= 3.0.8, PHP 4 >= 4.0b2)

    strip_tags -- Strip HTML and PHP tags from a string

    Description

    string strip_tags (string str [, string allowable_tags])

    This function tries to strip all HTML and PHP tags from the given string. It errors on the side of caution in case of incomplete or bogus tags. It uses the same
    tag stripping state machine as the fgetss() function.

    You can use the optional second parameter to specify tags which should not be stripped.

    Note: Allowable_tags was added in PHP 3.0.13, PHP4B3


    Love those manuals...

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    Atlanta, GA
    Posts
    10
    Rep Power
    0

    I was aware of strip_tags, however I wasn't aware that you could include allowable strings with it. Thanks for the info..

    However, I still would like to know the answer to what's wrong with my own regular expression for stripping out just for my own knowledge if I need to use it for something else

    Thanks Sepodiati

Similar Threads

  1. seperate html tags from text in string
    By sweetpotatoe in forum PHP Development
    Replies: 3
    Last Post: January 28th, 2004, 10:39 AM
  2. How to get client email??Help plz
    By Gecko22 in forum ASP Programming
    Replies: 12
    Last Post: January 22nd, 2004, 01:40 PM
  3. not returning records when it should
    By aliaga61 in forum ASP Programming
    Replies: 3
    Last Post: January 16th, 2004, 10:57 AM
  4. 'Object required' error
    By aliaga61 in forum ASP Programming
    Replies: 1
    Last Post: January 16th, 2004, 08:48 AM
  5. regular expressions: returning img tags with no alt.
    By OhLordy in forum Perl Programming
    Replies: 2
    Last Post: January 7th, 2004, 10:10 AM

IMN logo majestic logo threadwatch logo seochat tools logo