How to parse an ini-file containing special characters with "parse_ini_file"?
character-encoding, ini, parsing, php
Solution
The following is an assumption because your question does not document technically so far what the actual cause is.
However what can be said is that you have a character encoding related issue here.
Save your INI file with the UTF-8 encoding and this should work. I assume your PHP script outputs UTF-8 to the browser and the values in the INI file are not UTF-8 encoded. If you save the INI file with UTF-8 encoding, this should then work.
The key point here is not so much the "UTF-8" but that you save the INI file with the right character encoding that is expected from the application you use. For example if your application uses ISO-8859-1, then save the INI file with the ISO-8859-1 encoding.
Both - the INI file and the PHP script - need to speak the same "language".
You can add a "translator" that is able to help you bring two different "languages" together. Such a translator (or more correctly re-encoder) is `iconv`:
$ini_iso88591 = file_get_contents("sad - Kopie (6)/folder.ini");
$ini_utf8 = iconv("ISO-8859-1", "UTF-8", $ini_iso88591);
$ini_array = parse_ini_string($ini_utf8, TRUE);
Problem
I have a folder.ini containing: ``` [Labels] ; Ordnername name=testverzeichnis ; Ordnerbeschreibung description=verzeichnis zu testen von daten [Contents] [Publisher] publisher=e-Solutions copyright=André Reinhardt ``` and when I parse it with `parse_ini_file()` I got `�` instead of `é`. My Code: ``` $ini_array = parse_ini_file("sad - Kopie (6)/folder.ini", TRUE); print_r($ini_array); ``` I tried to replace `é` with `é` but then my string is `0`. Addition: This code to view the content works with both, `é` and `é`: ``` echo file_get_contents($directories[$i]."/folder.ini") ``` How can I avoid this?