Page 1 of 1

strip css

Posted: Wed Sep 21, 2005 3:30 am
by s.dot
Hmm.. is there a function for strippin css ? similar to strip_tags? or would I need to use a regex?

Re: strip css

Posted: Wed Sep 21, 2005 3:47 am
by n00b Saibot
scrotaye wrote:Hmm.. is there a function for strippin css ? similar to strip_tags? or would I need to use a regex?
strip_css() maybe :P well, i think strip_tags should do it, since css is also a tag - style tag :wink:

Posted: Wed Sep 21, 2005 3:51 am
by s.dot
strip_tags() will strip the tags :P but not the information between the tags

Code: Select all

<style type="text/css">
.class {
  color: #000000;
}
</style>
running strip_tags() on that will output ".class { color: #000000; }"

edit: I probably should've clarified better :P I would like to strip out the information between the <style </style> tags

Posted: Wed Sep 21, 2005 4:00 am
by Jenk
regex it then, if that is all :)

Code: Select all

$string = preg_replace("/<style type=(\"|')(.+)(\"|')>(.+)<\/style>/i", "<style type=\"$1\"></style>", $string);

Posted: Wed Sep 21, 2005 4:10 am
by n00b Saibot
Home-made Cookies :P

Code: Select all

<?

$tags =<<<END
<style type="text/css">
.class { 
  color: #000000; 
}
</style>
[ Jean Claude Van Dame ]
<style type="text/css">
.class { 
  color: #000000; 
}
</style>
END;

function strip_css($body)
{
return preg_replace('|<\w+[^>]>.*?</\w+[^>]>|is', 'Tags Replaced', $body);
}

print "Strip Tags: ".strip_tags($tags)."<br />";
print "My Strip Tags: ".strip_css($tags);
?>
edit: tooo late :(