Welcome Guest, Not a member yet? Register   Sign In
problem with url_title
#1

[eluser]Berserk[/eluser]
hi there,
i got this problem with url_title:
string: dark tranq
Result:
+ localhost: dark-tranq
+ but on server: darktranq (space removed :-?? )

need someone help me Sad

my url_title function (customized) :

Code:
function url_title($str, $separator = 'dash')
    {
        //replace_vie($str);
        if ($separator == 'dash')
        {
            $search        = '_';
            $replace    = '-';
        }
        else
        {
            $search        = '-';
            $replace    = '-';
        }
        
        
        $trans = array(
        'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',
        'd'=>'đ|Đ',
        'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',
        'i'=>'í|ì|ỉ|ĩ|ị',
        'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',
        'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',
        'y'=>'ý|ỳ|ỷ|ỹ|ỵ',
        'A'=>'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
        'D'=>'Đ|Đ',
        'E'=>'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
        'I'=>'Í|Ì|Ỉ|Ĩ|Ị',
        'O'=>'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
        'U'=>'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
        'Y'=>'Ý|Ỳ|Ỷ|Ỹ|Ỵ',        
        );
        foreach ($trans as $key => $val)
        {
        $str = preg_replace("/($val)/i",$key,$str);
        }
        
        
        
        $trans = array(
                        $search                                => $replace,
                        "\s+"                                => $replace,
                        $replace."+"                        => $replace,
                        "[^a-z0-9".$replace."]"                => '',                    
                        $replace."$"                        => '',
                        "^".$replace                        => '',
                       );

        $str = strip_tags(strtolower($str));
    
        foreach ($trans as $key => $val)
        {
            $str = preg_replace("#".$key."#", $val, $str);
        }
    
        return trim(stripslashes($str));
#2

[eluser]uptime[/eluser]
First of all, you may have forgotten the last "}". (the one that ends the function block.)

Second, the code looks OK besides this (it's in the second $trans array):

Code:
"[^a-z0-9".$replace."]" => '',

$replace equals a dash '-' and should be escaped (here's what it looks at that point "[^a-z0-9-]").

You should probably escape it:
Code:
"[^a-z0-9\\" . $replace . "]" => '',

Not sure that's your problem, I got what you're getting locally (a dash) using PHP 5.3.0 and PCRE 7.9.

If you're still getting different results, I'd suggest you start comparing PHP and PCRE lib versions, it's very important to have the same environment as the server (or at least, as close as you can) to avoid such problems.
#3

[eluser]bonatoc[/eluser]
Thanks for the foreign accents hack. I had trouble while translating french cities names into SEO friendly URLs.

Do you know of any cyrillic translation rules available ?

I know the new standards will allow for cyrillic and arabic URLs, but in the meantime...




Theme © iAndrew 2016 - Forum software by © MyBB