/** * Convert to valid slug. * @param string $value value to convert * @param string $default default value * @return string */ static function toSlug($value, $default = 'n-a') { // replace non letter or digits by - $text = preg_replace('~[^\\pL\\d]+~u', '-', $value); // trim $text = trim($text, '-'); // transliterate $text = v::translit($text); if (function_exists('iconv')) { $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); } // lowercase $text = strtolower($text); // remove unwanted characters $text = preg_replace('~[^-\\w]+~', '', $text); return $text != '' ? $text : $default; }