Back to PhocacartText class

Method stringURLSafe

public static
stringURLSafe
(mixed $string, mixed $language = '')

Method stringURLSafe - Source code

public static function stringURLSafe($string, $language = '')
{
    // Remove any '-' from the string since they will be used as concatenaters
    $str = str_replace('-', ' ', $string);
    // Transliterate on the language requested (fallback to current language if not specified)
    $lang = $language == '' || $language == '*' ? JFactory::getLanguage() : Language::getInstance($language);
    $str = $lang->transliterate($str);
    // Trim white spaces at beginning and end of alias and make lowercase
    $str = trim(StringHelper::strtolower($str));
    // Remove any duplicate whitespace, and ensure all characters are alphanumeric
    $str = preg_replace('/(\\s|[^A-Za-z0-9\\-_])+/', '-', $str);
    // Trim dashes at beginning and end of alias
    $str = trim($str, '-');
    return $str;
}