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 4334038
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:28:28+00:00 2026-05-21T10:28:28+00:00

I would like to make use of somehting like [parse_ini_file][1]. Lets say for instance

  • 0

I would like to make use of somehting like [parse_ini_file][1].

Lets say for instance I have a boot.ini file that I will load for further procedure:

    ;database connection settings
[database]
type        =   mysql;
host        =   localhost;
username    =   root;
password    =   "";
dbName      =   wit;

However, I would like to have it in a different way as the php array would be:

$ini['database']['whatever']

So first of all I would like to have my boot.ini like this structure:

;database settings (comment same style)
db.host1.type = mysql;
db.host1.host = localhost;
db.host1.username = root;
db.host1.password = "";
db.host1.dbName = wit;

db.host2.type = mysql;
db.host2.host = otherHost;
db.host2.username = root;
db.host2.password = "";
db.host2.dbName = wit;

So when I now access the file I would like to access it this way:

$ini['db']['host1']['whatever']

And on top of that I would like to do it via OOP so lets say:
$ini->db->host1->whatever

or `$ini->db->host1` 

will return an array with all the attributes such as type, host, username, password and the dbName;

I appreciate anykind of help. Thank you very much in advance.

  [1]: http://uk2.php.net/manual/en/function.parse-ini-file.php
  • 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-21T10:28:29+00:00Added an answer on May 21, 2026 at 10:28 am

    Well, you need to postprocess the parse_ini_file result array then.

    $ini_array = parse_ini_file("bootstrap.ini");
    
    $ini = new stdclass;
    foreach ($ini_array as $key=>$value) {
        $c = $ini;
        foreach (explode(".", $key) as $key) {
            if (!isset($c->$key)) {
                $c->$key = new stdclass;
            }
            $prev = $c;
            $c = $c->$key;
        }
        $prev->$key = $value;
    }
    

    Update Hackety-Hack. Now using an extra $prev to unset the last object level again. (A for loop to detect the last $key would have worked better).

    If you want to use the array syntax and the object syntax, then replace the new stdclass with new ArrayObject(array(), 2);.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make use of request scoped beans in my app. I
I would like to make some of my code more monadic and to use
I would like to use python to make system calls to programs and time
I use ancestry to make a tree of goals. I would like to send
I have a string like 1.898, -1.456, 233.556, 34546.8 How would I make an
I would like make a script using PHP (probably need JS) to send POST
I would like make an extension method for the generic class A which takes
I would like to make sure my classes are robust - even if they
I would like to make a password and username entry field. And a submit

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.