Manuel Bürge Manuel Bürge - 2 months ago 6x
Ini Question

Wrong output of .ini file after parsing

I try to get values with php of an ini file which looks like this:

key = yFrTYcqH116ZL|XOJnMCLrLUf@RfqrNB
iv = 35jL|HRNSDhn38T39MK9wdN26CkcYRKT

The ini file is created with a python script, which chooses random chars of a string.

The string looks like this:

string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=@#|'

Finally I try to parse the ini file and get it's values:

$key_ini = parse_ini_file("..\key.ini");
$key = $key_ini['key'];
$iv = $key_ini['iv'];

echo $key;
echo '<br>';
echo $iv;

The output is pretty weird:


May is it possible that I have used an invalid character in the string or is the format of the ini file wrong?

Thanks in advance


In an .ini file, use double quotes "" to indicate string, so it will be parsed without modification. To solve your problem you can either double quote the values in your .ini file, example:

key = "yFrTYcqH116ZL|XOJnMCLrLUf@RfqrNB"
iv = "35jL|HRNSDhn38T39MK9wdN26CkcYRKT"

OR, you can tell parse_ini_file() to use the INI_SCANNER_RAW mode, example:

$key_ini = parse_ini_file("..\key.ini", false, INI_SCANNER_RAW);

Although, for some reasons I personally prefer the double quotes.