strip css

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

strip css

Post by s.dot »

Hmm.. is there a function for strippin css ? similar to strip_tags? or would I need to use a regex?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Re: strip css

Post 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:
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

regex it then, if that is all :)

Code: Select all

$string = preg_replace("/<style type=(\"|')(.+)(\"|')>(.+)<\/style>/i", "<style type=\"$1\"></style>", $string);
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 :(
Post Reply