0

INI data looks like this:

[datasources]
live.dsn   = "mysql:host=localhost;dbname=main"
live.user  = "root"
live.pass  =

I'm using parse_ini_file().

  • with INI_SCANNER_RAW live.dsn is parsed incorrectly ("mysql:host)
  • with INI_SCANNER_NORMAL the value of live.dsn is correct

But I can't use INI_SCANNER_NORMAL because then it will also replace constants, "on" with 1 and so on (don't want that)... Is there any fix or do I have to create my own parser?

I'm using PHP 5.3.

hakre
  • 193,403
  • 52
  • 435
  • 836
nice ass
  • 16,471
  • 7
  • 50
  • 89

1 Answers1

1
var_dump(parse_ini_string('[datasources]
live.dsn   = "mysql:host=localhost;dbname=main"
live.user  = "root"', false, INI_SCANNER_RAW));

=>

array(2) {
  ["live.dsn"]=>
  string(32) "mysql:host=localhost;dbname=main"
  ["live.user"]=>
  string(4) "root"
}

I am unable to reproduce it. (It also doesn't work for parse_ini_file.) It works in PHP 5.3 and PHP trunk...


I see that this was a bug in older PHP versions, see https://bugs.php.net/bug.php?id=51094 . Simply upgrade, then it should work. If you're unable to upgrade, you really have to write your own ini parser.

bwoebi
  • 23,637
  • 5
  • 58
  • 79
  • @OneTrickPony Ok, then it was a bug... Updated my answer. (I have PHP 5.3.15, the first version which works xD) – bwoebi Apr 18 '13 at 16:20
  • Ended up using something like [this](http://www.php.net/manual/en/function.parse-ini-string.php#94192). Probably slower, but it seems I have no choice :( – nice ass Apr 19 '13 at 01:18