Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function strip_tags_attributes($string, $allowtags = NULL, $allowattributes = NULL)
- {
- /* Credits to [email protected] (http://www.php.net/manual/en/function.strip-tags.php#91498) */
- $string = strip_tags($string,$allowtags);
- if (!is_null($allowattributes))
- {
- if(!is_array($allowattributes))
- {
- $allowattributes = explode(",",$allowattributes);
- }
- if(is_array($allowattributes))
- {
- $allowattributes = implode(")(?<!",$allowattributes);
- }
- if (strlen($allowattributes) > 0)
- {
- $allowattributes = "(?<!".$allowattributes.")";
- }
- $string = preg_replace_callback("/<[^>]*>/i",create_function('$matches', 'return preg_replace("/ [^ =]*'.$allowattributes.'=(\"[^\"]*\"|\'[^\']*\')/i", "", $matches[0]);'),$string);
- }
- return $string;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment