15

The documentation on parse_ini_file states that you can't use these chars {}|&~![()^" in the value. Is there some way to escape these chars? I need to use them. Normal escaping with \ doesn't seem to work.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Martin
  • 5,197
  • 11
  • 45
  • 60

2 Answers2

20

The manual says those characters can not be used in the key -- the opposite of the value. To use them in values, double-quote the string.

Amy B
  • 17,874
  • 12
  • 64
  • 83
  • 2
    "Characters {}|&~![()^" must not be used anywhere in the key and have a special meaning in the value." Okay not forbidden but it doesn't parse if i put a () in a double-quoted string value. – Martin Mar 29 '10 at 11:18
  • 2
    What about double quotes? –  Mar 08 '17 at 15:01
  • Double quoted string does not work the same way if they span multiple lines - then, they work like not quoted string, just with newlines –  Mar 15 '17 at 19:26
6

Try using INI_SCANNER_RAW (from the same documentation) for scanner_mode:

parse_ini_file ( $filename, true, INI_SCANNER_RAW );
VadimBelov
  • 671
  • 6
  • 3
  • This can work if you happen to parse your own `.ini` file for your own usage. This will not cover the case where you change a `.ini` that is consumed by some other code (including the `.ini` that are read at PHP start). – Stéphane Gourichon Jun 26 '19 at 13:19