Let me explain situation closer.
- Im working on some old company server with PHP 4. There is Windows 2000NT installed and a databaze that I can open with Microsoft Access 2000.
- There is no any option to set character encoding (unlike in phpMyAdmin), but I can read that characters in MS Access properly.
- Im extracting data from that database in my .php files and displaying it on my website, but characters like:
ü, ä, ß
are displayed wrong, like this: �
- All php/html files are saved by some old version of Notepad++ as UTF-8 encoding and containing:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
I read some theory about character encoding, history of character encoding and almighty UTF-8 that will solve all your problems, which is simply not true. What could be wrong?
First, identify what byte values your broken characters have exactly. Without knowing you cannot identify the encoding like to be used.
echo urlencode($string_with_umlauts);
This will print all non-ascii characters as percent-encoded hex values. Note that this function is meant for some other purpose, but it'll help in this case also.
Then lookup the bytes in encoding tables like Wikipedia and be sure what you have there.
The last step: Add a transformation layer to your database access logic that converts from the encoding you saw to UTF-8 with iconv functions.
Well, I found solution:
function decode($string){
$string = urlencode($string);
$string = str_replace('%DF','ß',$string);
$string = str_replace('%E4','ä',$string);
$string = str_replace('%F6','ö',$string);
$string = str_replace('%2B','+',$string);
$string = str_replace('%FC','ü',$string);
$string = str_replace('%26','&',$string);
$string = str_replace('%2F','/',$string);
$string = str_replace('%0A','',$string);
$string = str_replace('%0D','',$string);
$string = str_replace('%40','@',$string);
$string = str_replace('%2C',',',$string);
$string = str_replace('%E1','á',$string);
$string = str_replace('%D3','ó',$string);
$string = str_replace('+',' ',$string);
return $string;
}
But isn't there any better solution?