nice ass
nice ass

Reputation: 16719

PHP RAW INI parser fails to parse values correctly

INI data looks like this:

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

I'm using parse_ini_file().

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.

Upvotes: 0

Views: 337

Answers (1)

bwoebi
bwoebi

Reputation: 23787

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.

Upvotes: 1

Related Questions