Guest User

Untitled

a guest
Jun 18th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2. function strip_tags_attributes($string, $allowtags = NULL, $allowattributes = NULL)
  3. {
  4.     /* Credits to [email protected] (http://www.php.net/manual/en/function.strip-tags.php#91498) */
  5.     $string = strip_tags($string,$allowtags);
  6.     if (!is_null($allowattributes))
  7.     {
  8.         if(!is_array($allowattributes))
  9.         {
  10.             $allowattributes = explode(",",$allowattributes);
  11.         }
  12.  
  13.         if(is_array($allowattributes))
  14.         {
  15.             $allowattributes = implode(")(?<!",$allowattributes);
  16.         }
  17.  
  18.         if (strlen($allowattributes) > 0)
  19.         {
  20.             $allowattributes = "(?<!".$allowattributes.")";
  21.         }
  22.  
  23.         $string = preg_replace_callback("/<[^>]*>/i",create_function('$matches', 'return preg_replace("/ [^ =]*'.$allowattributes.'=(\"[^\"]*\"|\'[^\']*\')/i", "", $matches[0]);'),$string);
  24.     }
  25.    
  26.     return $string;
  27. }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment