Clean les vilains tag word
Submitted by Sir Squall on Wed, 08/04/2010 - 17:02
Il y a des jours comme sa ou on doit importer des articles, et on s'apperçois que les webmasters qui on gérer le contenu on fait de vilain copier coller depuis Word, ce qui nous donne quelque chose comme sa :
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
C'est pas très joli, alors j'ai trouvé une petite lib bien pratique qui s'appelle "HTMLPurifier" (sa donne comme nom), très simple d'utilisation et qui fonctionne très bien, exemple:
require_once $path.'/htmlpurifier/library/HTMLPurifier.auto.php';//Delete de bad coding in the body and teaser (like word) $config = HTMLPurifier_Config::createDefault(); $config->set('Core.Encoding', 'UTF-8'); $config->set('HTML.Doctype', 'HTML 4.01 Transitional'); $config->set('AutoFormat.AutoParagraph', true); $purifier = new HTMLPurifier(); $data->introtext = $purifier->purify($data->introtext); $data->fulltexte = $purifier->purify($data->fulltexte);
Et elle est disponible a http://htmlpurifier.org/
C'est fait !!!
Tags:







1 response to "Clean les vilains tag word"
1. je sais pas si tu as vu qu'il