Different encodings on different servers?

I just tested my web application locally, everything works fine, but after loading the server behavior it behaves differently. I use the formatiraj_string_url function to convert diacritical characters and get a clean url ... locally it works fine, but on the server this function does not convert them the same way.

A few days ago, I tested this on some third server, and it worked fine. Now I download the web to check it again on this third server, but I'm just wondering what could be causing this 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 the server, this was an error:

 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 did not have this problem

+2
php apache str-replace
12 Oct '09 at 19:25
source share
2 answers

What encoding is your file in?

Since you wrote the characters that you would like to replace directly in your code, they are encoded as strings in any encoding that the file uses. If this encoding is different from what you get from the browser, your functions will not work.

An important point that you need to keep in mind is to constantly monitor the encoding into which your lines are encoded and convert if necessary.

Take a look at the Nordmanns Koreans Frequently Asked Questions about PHP encodings.

+2
Oct 12 '09 at 20:10
source share

I recommend that you use existing, proven code for this. I believe that all of these functions involve input and output of UTF-8 7-bit ASCII:

+3
Oct 12 '09 at 21:14
source share



All Articles