MayThrow
MayThrow

Reputation: 2201

How to use a configuration file for controlling variables

I'm coding a theme and i want to create a configuration file (maybe ini) to control variables in the theme For example, I want to have a file with simple content like this

navigation: 1;
site_name: MYSITE;

^ dunno if the syntax is right...just an example

And then i want to use that file to show the content stored in those variables.

for example :

shows the value entered in the file i also want to show/hide specific content based on the Boolean value entered in the value (navigation: 1 or 0) something like

I hope i'm understandable. I'm a noob in PHP :'>

Upvotes: 0

Views: 791

Answers (2)

Bradmage
Bradmage

Reputation: 1231

I moved away from .ini files when I discovered json. Makes everything so easy.

$filePath = "/var/www/config.json";

// Puts the config into an array
$config = json_decode(file_get_contents($filePath));

// Saves array back to config file
file_put_contents($filePath, json_encode($config));

Upvotes: 2

Amber
Amber

Reputation: 527378

Perhaps take a look at parse_ini_file().

Upvotes: 1

Related Questions