有没有parse_ini_file()的特殊行为我应该知道吗? [关闭]

I have a quite big INI file (around 100kb and over 2000 lines) which I am trying to parse with PHP: $ini_array = parse_ini_file("config.ini");

But the function throw a warning: PHP Warning: syntax error, unexpected '(' in config.ini on line 1334 in ...

Looking at line 1334 won't show any syntax error. Then I read this answer :

Short answer:

Don't trust the line numbers, look for a syntax error in the lines before the line mentioned in the error.

I am confident that there is no error in the file because its used in production by an other tool wrote in Pascal.

So,

  • How I could check the file manually for errors ?

  • And if no syntax error exist in the file, is there a behavior of parse_ini_file() I should be aware of ?

I found in the PHP manual :

Characters ?{}|&~![()^" must not be used anywhere in the key and have a special meaning in the value.

From PHP 5.3.0 we can set a third parameter scanner_mode. So calling parse_ini_file() with INI_SCANNER_RAW as third parameter did the trick - the function do not evaluate values.

By default the function use the INI_SCANNER_NORMAL mode and evaluate values.

You could try a "manual" approch, dichotomy search.

  1. Remove lines after the line 1333.
  2. Then remove lines before by (large) blocks until you have no error.
  3. Add lines by smaller blocks until you have error again.

You will find the error.