note 59960 added to function.preg-replace
| From: | istvan dot csiszar at weblab dot hu | Date: | Wed, 21 Dec 2005 09:53:03 +0000 |
| Subject: | note 59960 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100510@lists.php.net to get a copy of this message | ||
This is an addition to the previously sent removeEvilTags function. If you don't want to remove
the style tag entirely, just certain style attributes within that, then you might find this piece of
code useful:
<?php
function removeEvilStyles($tagSource)
{
// this will leave everything else, but:
$evilStyles = array('font', 'font-family', 'font-face',
'font-size', 'font-size-adjust', 'font-stretch',
'font-variant');
$find = array();
$replace = array();
foreach ($evilStyles as $v)
{
$find[] = "/$v:.*?;/";
$replace[] = '';
}
return preg_replace($find, $replace, $tagSource);
}
function removeEvilTags($source)
{
$allowedTags =
'<h1><h2><h3><h4><h5><a><img><label>'.
'<p><br><span><sup><sub><ul><li><ol>'.
'<table><tr><td><th><tbody><div><hr><em><b><i>';
$source = strip_tags(stripslashes($source), $allowedTags);
return trim(preg_replace('/<(.*?)>/ie',
"'<'.removeEvilStyles('\\1').'>'", $source));
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59960
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59960&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59960&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59960&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59960&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59960&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59960&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59960&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59960&report=yes
Search -- http://master.php.net/manage/user-notes.php