note 69664 added to function.strip-tags

From: Date: Thu, 14 Sep 2006 13:32:39 +0000
Subject: note 69664 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-117153@lists.php.net to get a copy of this message
I made this function with regular expression to remove some style properties from tags based in other exaples here ;D <? function removeAttributes($htmlText) { $stripAttrib = "'\\s(class)=\"(.*?)\"'i"; //remove classes from html tags; $htmlText = stripslashes($htmlText); $htmlText = preg_replace($stripAttrib, '', $htmlText); $stripAttrib = "/(font\-size|color|font\-family|line\-height):\\s". "(\\d+(\\x2E\\d+\\w+|\\W)|\\w+)(;|)(\\s|)/i"; //remove font-style,color,font-family,line-height from style tags in the text; $htmlText = stripslashes($tagSource); $htmlText = preg_replace($stripAttrib, '', $htmlText); $htmlText = str_replace(" style=\"\"", '', $htmlText); //remove empty style tags, after the preg_replace above (style=""); return $htmlText; } function removeEvilTags($source) { return preg_replace('/<(.*?)>/ie', "'<'.removeEvilAttributes('\\1').'>'", $source); } ?> Usage: <? $text = '<p style="line-height: 150%; font-weight: bold" class="MsoNormal"><span style="font-size: 10.5pt; line-height: 150%; font-family: Verdana">Com o compromisso de pioneirismo e aprimoramento, caracter&iacute;sticas da Oftalmocl&iacute;nica, novos equipamentos foram adquiridos para exames e diagn&oacute;sticos ainda mais precisos:</span></p>'; //This text is in brazillian portuguese ;D echo htmlentities(removeEvilTags($text))."\r\n"; //This is return: <p style="font-weight: bold"><span>Com o compromisso de pioneirismo e aprimoramento, caracter&iacute;sticas da Oftalmocl&iacute;nica, novos equipamentos foram adquiridos para exames e diagn&oacute;sticos ainda mais precisos:</span></p> ?> W0oT ! This is fantastic ! If you find an error, please report me to my mail ;D (Y) ---- Server IP: 200.185.109.13 Probable Submitter: 200.139.120.29 (proxied: 192.168.0.8) ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/69664 Del: integrated -- https://master.php.net/note/delete/69664/integrated Del: useless -- https://master.php.net/note/delete/69664/useless Del: bad code -- https://master.php.net/note/delete/69664/bad+code Del: spam -- https://master.php.net/note/delete/69664/spam Del: non-english -- https://master.php.net/note/delete/69664/non-english Del: in docs -- https://master.php.net/note/delete/69664/in+docs Del: other reasons-- https://master.php.net/note/delete/69664 Reject -- https://master.php.net/note/reject/69664 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117153) next »