public static function clean($str, array $options = array())
{
if (is_array($options['clean'])) {
$clean = $options['clean'];
} else {
$clean = array('method' => is_bool($options['clean']) ? 'text' : $options['clean']);
}
switch ($clean['method']) {
case 'text':
$clean += array('word' => '[\\w,.]+', 'gap' => '[\\s]*(?:(?:and|or|,)[\\s]*)?', 'replacement' => '');
$before = preg_quote($options['before'], '/');
$after = preg_quote($options['after'], '/');
$kleenex = sprintf('/(%s%s%s%s|%s%s%s%s|%s%s%s%s%s)/', $before, $clean['word'], $after, $clean['gap'], $clean['gap'], $before, $clean['word'], $after, $clean['gap'], $before, $clean['word'], $after, $clean['gap']);
$str = preg_replace($kleenex, $clean['replacement'], $str);
break;
case 'html':
$clean += array('word' => '[\\w,.]+', 'andText' => true, 'replacement' => '');
$kleenex = sprintf('/[\\s]*[a-z]+=(")(%s%s%s[\\s]*)+\\1/i', preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/'));
$str = preg_replace($kleenex, $clean['replacement'], $str);
if ($clean['andText']) {
return static::clean($str, array('clean' => array('method' => 'text')) + $options);
}
break;
}
return $str;
}