Putra Fajar Hasanuddin
Putra Fajar Hasanuddin

Reputation: 1193

PHP - parse_ini_file with | value

parse_ini_file() cant read value something like this:

bot_virtualhostname = |c00FF3366VIVA
bot_commandtrigger = !

i cant give double quotes, bcoz ghost++ https://code.google.com/p/ghostplusplus/ will use " as value too.

can someone give alternative to read value? im newbie in PHP

Upvotes: 0

Views: 190

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78994

Might have to use some of the file() options to get rid of newlines and/or trim $key and $value if spaces aren't consistant around the =:

$lines = file('/path/to/file.ini', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

foreach($lines as $line) {
    list($key, $value) = explode(' = ', $line);
    $result[$key] = $value;
}

If the inability to use " is the only peculiarity and you need the sections etc.

$string = file_get_contents('/path/to/file.ini');
$string = preg_replace('/(\s?=\s?)(.*)\r/', '$1"$2"', $string);
$result = parse_ini_string($string);

Upvotes: 1

Related Questions