library/HTMLPurifier/AttrDef/HTML/Nmtokens.php

Go to the documentation of this file.
00001 <?php
00002 
00010 class HTMLPurifier_AttrDef_HTML_Nmtokens extends HTMLPurifier_AttrDef
00011 {
00012     
00013     public function validate($string, $config, $context) {
00014         
00015         $string = trim($string);
00016         
00017         // early abort: '' and '0' (strings that convert to false) are invalid
00018         if (!$string) return false;
00019         
00020         // OPTIMIZABLE!
00021         // do the preg_match, capture all subpatterns for reformulation
00022         
00023         // we don't support U+00A1 and up codepoints or
00024         // escaping because I don't know how to do that with regexps
00025         // and plus it would complicate optimization efforts (you never
00026         // see that anyway).
00027         $matches = array();
00028         $pattern = '/(?:(?<=\s)|\A)'. // look behind for space or string start
00029                    '((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)'.
00030                    '(?:(?=\s)|\z)/'; // look ahead for space or string end
00031         preg_match_all($pattern, $string, $matches);
00032         
00033         if (empty($matches[1])) return false;
00034         
00035         // reconstruct string
00036         $new_string = '';
00037         foreach ($matches[1] as $token) {
00038             $new_string .= $token . ' ';
00039         }
00040         $new_string = rtrim($new_string);
00041         
00042         return $new_string;
00043         
00044     }
00045     
00046 }
00047 

Generated on Thu Jun 19 18:47:25 2008 for HTMLPurifier by  doxygen 1.5.3