Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse ini file with brackets

Tags:

php

parsing

ini

I have an .ini files which contains brackets ( ) As php.net recomend I parse.ini file with parse_ini_file() functio, so let's say my code looks like:

$ini = parse_ini_file('files/models.ini');

then error looks like:

Warning: syntax error, unexpected '(' in files/models.ini on line 4 in \index.php on line 48

This is text from line 4

00name1=100 08/82-11/90 (443/445) Typový sešit [V] [27]

Problem is I am getting this file from outsite and I can not change it,

From multiple sites I notice that some words have special meaning in ini file like "null" "true" "no" "yes" but this is not this kind of situation.

So guys can somebody advise me what I am doing wrong or if this is impossible is there any workaround?

like image 725
Andurit Avatar asked Jul 22 '15 13:07

Andurit


1 Answers

You can use the option INI_SCANNER_RAW:

$ini = parse_ini_file('files/models.ini', false, INI_SCANNER_RAW);

From the documentation:

If INI_SCANNER_RAW is supplied, then option values will not be parsed.

Result from my test:

$ php test.php
array(1) {
  ["foo"]=>
  string(9) "foo (bar)"
  ["00name1"]=>
  string(49) "100 08/82-11/90 (443/445) Typový sešit [V] [27]"
}
like image 127
Gerald Schneider Avatar answered Nov 13 '22 05:11

Gerald Schneider