WordOff – Clean Your Code
Many times we like the way a table looks when generated, but when you look at the code you see more style properties and non-XHTML compliant attributes that make shun away. The same thing happens when pasting from Word into a WYSIWYG. Trying to remove the unnecessary code can be laborious. That’s where WordOff comes in handy.
WordOff is a simple optimizer that strips unnecessary formatting from a chunk of HTML.
It uses the following rules to strip the extra stuff from your code:
- Attributes are removed for all elements except <a>s
- <span>s and <div>s are removed
- Empty elements are removed
- Consecutive line breaks are reduced to two
WordOff web app comes especially in handy when clients (like mine) give you a ten page Word document they want to be posted. I’ve seen more style=”MsoNormal”’s than I can count. WordOff fixes all this for me.





4 Responses to WordOff – Clean Your Code
You can achieve the same in PHP:
function stripAttributes($string)
{
$string=preg_replace(’/()/’, ‘${1}href..;,;..${2}’, $string);
$string=preg_replace(’/()/’, ‘${1}id..;,;..${2}’, $string);
$string=preg_replace(’/()/’, ‘${1}class..;,;..${2}’, $string);
while(preg_match(’/()/’, $string)) $string=preg_replace(’/()/’, ‘${1}${4}’, $string);
$string=str_replace(’..;,;..’, ‘=’, $string);
return $string;
}
I found this at http://www.php.net/strip_tags in a comment by mdw252 at psu dot edu. Looks neat I think I will try it as an output filter.
PHP Developer
10/14/2008 at 12:36 pm
Dude! I love your website but why have you not been updating it?
Tim
10/24/2008 at 4:46 pm
This is a great blog but its sad to see it not getting updated…..is it coming back?
Anthony
10/27/2008 at 11:12 pm
It would be nice if the idea of “theDailyapp” came back into play…
Mike
11/16/2008 at 1:00 pm