note 69663 added to function.strip-tags
| From: | bfmaster_duran at yahoo dot com dot br | Date: | Thu, 14 Sep 2006 13:31:07 +0000 |
| Subject: | note 69663 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117152@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ísticas da Oftalmoclínica, novos equipamentos foram adquiridos para
exames e diagnó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ísticas da Oftalmoclínica, novos
equipamentos foram adquiridos para exames e diagnó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/69663
Del: integrated -- https://master.php.net/note/delete/69663/integrated
Del: useless -- https://master.php.net/note/delete/69663/useless
Del: bad code -- https://master.php.net/note/delete/69663/bad+code
Del: spam -- https://master.php.net/note/delete/69663/spam
Del: non-english -- https://master.php.net/note/delete/69663/non-english
Del: in docs -- https://master.php.net/note/delete/69663/in+docs
Del: other reasons-- https://master.php.net/note/delete/69663
Reject -- https://master.php.net/note/reject/69663
Search -- https://master.php.net/manage/user-notes.php