Posted By


blubadger on 12/12/08

Tagged


Statistics


Viewed 108 times
Favorited by 0 user(s)

RemoveAttributesStyle


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function removeStyle($string) {
  2. $except = array('font-weight', 'text-decoration', 'color'); // declare your exceptions
  3. $allow = implode($except, '|');
  4. $regexp = '@([^;"]+)?(?<!'.$allow.'):(?!\/\/(.+?)\/)((.*?)[^;"]+)(;)?@is';
  5. $out = preg_replace($regexp, '', $string);
  6. $out = preg_replace('@[a-z]*=""@is', '', $out); // remove any unwanted style attributes
  7. return $out;
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.