strip css in style tags function?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm looking for a function to strip css markup from a string.
strip_tags() isn't doing the whole job.

I'm using rte to allows users to create html using a WYSIWYG
interface. The field that I'm storing the string in allows null; if
the user doesn't have any html, I would like to set the field to null
( whether the field is Null changes the behavior of the site ).

However, when a user completely empties out the text box of rte, there
is still a bunch of html and css. A blank rte box will return this as
a value:

<br /> <style type="text/css"> body { background: #FFF; } </style>

Running it through strip tags, I get this:
body { background: #FFF; }

But, I would like to know if there is no "content" in the string.
Ideally I'd like to run it through a function and get a 0-length
string as the output. Then if the string is 0-length, I know that I
can set the field to null.

Is there a pre-existing function out there that I can use, which does

Re: strip css in style tags function?

I wrote a function called strip_rte():

function trim_rte($string) {

        $replacements = array(
                "body {"
                , "background: #FFF;"
                , "}"
                , "\t"
                , "\n"
                , "&nbsp;"


        $string = str_replace(
                , ""
                , $string

        return $string;


Site Timeline