Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 856433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:14:06+00:00 2026-05-15T08:14:06+00:00

I am writing a PHP application targeted at non-geeks, non-programmers. I need to create

  • 0

I am writing a PHP application targeted at non-geeks, non-programmers. I need to create an option page with a bunch of “options” and then store those options…somewhere. Using a database application (MySQL/PostgreSQL/SQLite) is out of the question because it will require more configuration than the user needs to do (I don’t want the user to do any kind of configuration if he doesn’t want to). So the only solution left is to write the configuration to a configuration file. On the other hand, I also want that configuration file to be human-readable in case the user is a geek and he wants to edit the config file directly (or if he wants to edit the file remotely via SSH or any kind of reason…)

Here are the couple of potential solutions I found:

Using a JSON file…

…Retrieve the data from the file, using json_decode to convert the data, output it into HTML, retrieve any changes, encode back using json_encode, etc. You get the picture. There are a couple things that I don’t like about this method, the main one being that the encoded JSON data using PHP will no be well formatted and very hard to edit without being reformatted beforehand.

Using an XML file

I won’t describe that solution because I don’t really like it either…and I don’t know how to use XSLT and don’t really want to learn…and because it’s a pretty heavyweight solution, at least compared to the JSON solution. Correct me if I’m wrong.

Using an INI file

I love INI files, really I love them! I think they’re really the most readable, and it’s hard to mess up (ie: syntax errors). The problem with that solution is that there is no native way to write/edit an ini file. I found a topic showing a custom method to write one…that might be the solution I will adopt if I don’t find anything better…

Using two files

That last solution seems as reasonable as the INI solution. In fact, I could use an INI file as “input” (the file that the user would edit if he wants to) and an XML/JSON file as output (the file that will be edited by PHP every time the user changes options using the web front-end). At this point, the best solution would be to ask the user to reload the configuration manually if he edited the config file directly, so that the “output” file is always up to date.


I know none of the solutions above are perfect, and that’s why I created this topic to ask for advice. What is the best solution? Maybe (probably) I missed yet another solution.

One last thing: YAML isn’t a valid solution because it’s a lot easier to mess up the syntax if you’re not used to it. PHP is not a solution either because editing PHP with PHP is a pain. PHP is only a good solution if I want to retrieve some configuration but not edit it directly via a web front-end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:14:06+00:00Added an answer on May 15, 2026 at 8:14 am

    ini

    I’d write ini files, myself. As you said, the syntax is very simple, and that’s what you want in a config file. The ini format’s "key+value" pairing is exactly what you’d get with a database—without the database.

    Related SO you may have seen already: create ini file, write values in PHP

    Plus you can use parse_ini_file() to read it.

    XML

    XML isn’t all that bad. It may be more work to write it (and may not be as clear to the user as an ini file), but reading it is really easy.

    Create it:

    
    <?php
    // Create file
    $xml = new SimpleXMLElement( '<?xml version="1.0" ?><config></config>' );
    
    // Add stuff to it
    $xml->addChild( 'option1' );
    $xml->option1->addAttribute( 'first_name', 'billy' );
    $xml->option1->addAttribute( 'middle_name', 'bob' );
    $xml->option1->addAttribute( 'last_name', 'thornton' );
    $xml->addChild( 'option2' );
    $xml->option2->addAttribute( 'fav_dessert', 'cookies' );
    
    // Save
    $xml->asXML( 'config.xml' );
    ?>

    Read it:

    
    <?php
    // Load
    $config = new SimpleXMLElement( file_get_contents( 'config.xml' ) );
    
    // Grab parts of option1
    foreach( $config->option1->attributes() as $var )
    {
        echo $var.' ';
    }
    
    // Grab option2
    echo 'likes '.$config->option2['fav_dessert'];
    ?>
    

    Which gives you:

    billy bob thornton likes cookies

    Documentation for SimpleXML

    • SimpleXML Docs index
    • Basic Examples
    • Details on addChild() and addAttribute(), showing how to generate various XML structures (nested tags vs. attributes, for example)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 535k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would not use the RegisterWaitForSingleObject for this purpose. The… May 17, 2026 at 12:59 am
  • Editorial Team
    Editorial Team added an answer I've used: the lowest bit of a floating ADC input,… May 17, 2026 at 12:59 am
  • Editorial Team
    Editorial Team added an answer You missed the spider name in the crawl command. Use:… May 17, 2026 at 12:59 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm writing a PHP application with testability in mind, so my classes always ask
I'm writing a php application that submits via curl data to sign up for
I am writing a PHP application that will have the ability to edit settings
I'm currently writing a PHP application and drivers (classes) for the database engines. I
I'm writing a php application and was wondering if it's a bad idea to
Hay guys, I'm writing a PHP application to take a NZB file, grab the
Background: Experienced PHP developer with a mostly *nix background. I'm writing a PHP application
I'm writing a servlet-based application in which I need to provide a messaging system.
As many PHP programmers, I am a kind of CMS guy, but also training
How do I doc a variable number of parameters? I am writing an application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.