common/components/helpers/StringHelper.php
/**
     * Returns a string in a URL friendly format. This function is
     * recommended to be used on non-multibyte character sets. So 
     * this is not recommended for UTF-8, since certain PHP 
     * functions (like strtolower) should not be used on multibyte
     * strings.
     * @param string $str The input string.
     * @return string The URL friendly string.
     */
Returns a string in a URL friendly format. This function is
recommended to be used on non-multibyte character sets. So
this is not recommended for UTF-8, since certain PHP
functions (like strtolower) should not be used on multibyte
strings.
@param string $str The input string.
@return string The URL friendly string.
Returns a string in a URL friendly format . This function is recommended to be used on non - multibyte character sets . So this is not recommended for UTF - 8 since certain PHP functions ( like strtolower ) should not be used on multibyte strings . @param string $str The input string . @return string The URL friendly string .
public static function generateSlug($text)
    {
        $text = preg_replace('~[^\pL\d]+~u', '-', $text);
        $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
        $text = preg_replace('~[^-\w]+~', '', $text);
        $text = trim($text, '-');
        $text = preg_replace('~-+~', '-', $text);
        $text = strtolower($text);
        if (empty($text)) {
        return 'n-a';
        }
        return $text;
    }
public static function generateSlug ( $ text ) { $ text = preg_replace ( '~[^\pL\d]+~u' , '-' , $ text ) ; $ text = iconv ( 'utf-8' , 'us-ascii//TRANSLIT' , $ text ) ; $ text = preg_replace ( '~[^-\w]+~' , '' , $ text ) ; $ text = trim ( $ text , '-' ) ; $ text = preg_replace ( '~-+~' , '-' , $ text ) ; $ text = strtolower ( $ text ) ; if ( empty ( $ text ) ) { return 'n-a' ; } return $ text ; }
Returns a string in a URL friendly format.
Returns a string in a URL friendly format .
// replace non letter or digits by - // transliterate // remove unwanted characters // trim // remove duplicate - // lowercase // $str = trim(mb_strtolower($str)); // $str = preg_replace('/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/', 'a', $str); // $str = preg_replace('/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/', 'e', $str); // $str = preg_replace('/(ì|í|ị|ỉ|ĩ)/', 'i', $str); // $str = preg_replace('/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/', 'o', $str); // $str = preg_replace('/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/', 'u', $str); // $str = preg_replace('/(ỳ|ý|ỵ|ỷ|ỹ)/', 'y', $str); // $str = preg_replace('/(đ)/', 'd', $str); // $str = preg_replace('/[^a-z0-9-\s]/', '', $str); // $str = preg_replace('/([\s]+)/', '-', $str); // return $str;