Jon
Jon

Reputation: 1

writing a structured ini file from scratch via PhP

Im creating a picture viewer for a friend of mine but i am unable to use a database because his hosting doesn't allow one.

So im left trying to use ini files but i dont know how to write a structured ini file using php..i have successfully put together a script to read it via parse_ini_file() and break it down into it seperate categories and keys but i need to know how to write the acctuall structure if there isn't one already.

For example

[flowerpics]
picone = filelocation
pictwo = filelocation

[artpics]    
picone = filelocation

this is how im basing my parse_ini_file() script for ...so what if he wants to add a whole new category to this file ..lets say he wants to add "Rockandrollpics" ...how can i go about adding that into an ini file?

Upvotes: 0

Views: 311

Answers (2)

Andrej
Andrej

Reputation: 7504

If you don't use Mysql you can try to use SqlLite instead of. You needn't anything except php extension sqllite. Look at http://php.net/manual/en/book.sqlite.php for more info.

Upvotes: 0

Roman Pietrzak
Roman Pietrzak

Reputation: 615

If I were you, I would consider using some standard - like JSON, YAML, or even BJSON - it's almost as simple as INI files, but gives you more control about structuring the data. Your example with JSON:

"flowerpics"
{
    "picone" : "filelocation"; 
    "pictwo" : "filelocation"; 
}

"artpics"
{
    "picone" : "filelocation";
}

Upvotes: 1

Related Questions