note 69664 deleted from function.strip-tags by danbrown

From: Date: Sun, 17 May 2009 15:59:04 +0000
Subject: note 69664 deleted from function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154730@lists.php.net to get a copy of this message
Note Submitter: bfmaster_duran at yahoo dot com dot br ---- 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)

« previous php.notes (#154730) next »