public static function filter($text, $length = 60, $language = "", $file_name = false, $use_remove_list = true, $lower_case = true, $treat_underscore_as_space = true)
{
$text = self::downcode($text, $language);
if ($use_remove_list) {
// remove all these words from the string before urlifying
$text = preg_replace('/\\b(' . join('|', self::$remove_list) . ')\\b/i', '', $text);
}
// if downcode doesn't hit, the char will be stripped here
$remove_pattern = $file_name ? '/[^_\\-.\\-a-zA-Z0-9\\s]/u' : '/[^\\s_\\-a-zA-Z0-9]/u';
$text = preg_replace($remove_pattern, '', $text);
// remove unneeded chars
if ($treat_underscore_as_space) {
$text = str_replace('_', ' ', $text);
// treat underscores as spaces
}
$text = preg_replace('/^\\s+|\\s+$/u', '', $text);
// trim leading/trailing spaces
$text = preg_replace('/[-\\s]+/u', '-', $text);
// convert spaces to hyphens
if ($lower_case) {
$text = strtolower($text);
// convert to lowercase
}
return trim(substr($text, 0, $length), '-');
// trim to first $length chars
}