Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - Different charset on different server?

I've just tested locally my web application, everything works fine, but after uploading to server application behaves differently. I use function formatiraj_string_url to convert diacritic symbols and get clean url... locally it works fine but on server this function doesnt convert them the same way.

Few days earlier I tested this on some third server and it worked fine. Now I'm uploading web to test it again on this third server, but I just wonder what could really be the cause of such behavior?

function formatiraj_string_url($string)
    {
        $string = strtolower($string);

        $znak[0] = ' ';
        $znak[1] = '?';
        $znak[2] = '?';
        $znak[3] = '?';
        $znak[4] = '?';
        $znak[5] = '?';
        $znak[6] = '?';
        $znak[7] = '?';
        $znak[8] = '?';
        $znak[9] = '?';
        $znak[10] = '?';
        $znak[11] = 'Š';
        $znak[12] = 'Đ';
        $znak[13] = 'Č';
        $znak[14] = 'Ć';
        $znak[15] = 'Ž';
        $znak[16] = 'š';
        $znak[17] = 'đ';
        $znak[18] = 'č';
        $znak[19] = 'ć';
        $znak[20] = 'ž';
        $znak[21] = 'Š'; // ?
        $znak[22] = 'š'; // ?

        $zamjena[0] = '-';
        $zamjena[1] = 's';
        $zamjena[2] = 's';
        $zamjena[3] = 'd';
        $zamjena[4] = 'd';
        $zamjena[5] = 'c';
        $zamjena[6] = 'c';
        $zamjena[7] = 'c';
        $zamjena[8] = 'c';
        $zamjena[9] = 'z';
        $zamjena[10] = 'z';
        $zamjena[11] = 's';
        $zamjena[12] = 'd';
        $zamjena[13] = 'c';
        $zamjena[14] = 'c';
        $zamjena[15] = 'z';
        $zamjena[16] = 's';
        $zamjena[17] = 'd';
        $zamjena[18] = 'c';
        $zamjena[19] = 'c';
        $zamjena[20] = 'z';
        $zamjena[21] = 's';
        $zamjena[22] = 's';

        $string = str_replace($znak, $zamjena, $string);
        $new_string = preg_replace("/[^a-zA-Z0-9-s]/", "", $string);
        return $new_string;
    }

EDIT: Before str_replace, this function used preg_replace. On server this was the error showed:

Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 0 in /home2/sinjcom/public_html/sinj.com.hr/administracija/include/funkcije.php on line 200

But locally, I didn't have this problem

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I recommend you rely on existing, highly-tested code to do this. I believe all these functions assume UTF-8 input and output 7-bit ASCII:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...