0

Alright so I've read around for a little while and so far the best solution I've found so far is: How to read and write to an ini file with PHP

I've installed the pear package. included the required file initiated the class. as shown at: https://github.com/pear/Config_Lite/blob/master/docs/examples

However i am having troubles getting the variable.

this is my ini file:

[Account]
acct1.UserName = something1
acct1.Password = something2
acct1.Signature = something3
acct1.AppId = something4
# Subject is optional and is required only in case of third party authorization 
acct1.Subject = 

This is what i tried so far:

$config = new Config_Lite('$filename');
echo $config->get('Account', 'acct1.UserName');

It did not work and returned an error.

Thanks in advanced.

Community
  • 1
  • 1
Neta Meta
  • 4,001
  • 9
  • 42
  • 67
  • 1
    Shouldn't you get an error for the invalid filename? – mario Feb 13 '13 at 22:19
  • possible duplicate of [Why is PHP not replacing the variable in string?](http://stackoverflow.com/questions/11317743/why-is-php-not-replacing-the-variable-in-string) – mario Feb 13 '13 at 22:19
  • Mario thanks for opening my eyes. the filename was quoted bah – Neta Meta Feb 13 '13 at 22:20

2 Answers2

1

You can use acct1[UserName]=something1 instead of acct1.UserName=something1 and then in PHP access it by the following code:

[Account]
acct1[UserName]=something1

$config = new Config_Lite("$filename");
$config_acc = $config -> get('Account','acct1');
echo $config_db['UserName'];