Jump to content

Using parse_ini_file to parse an ini file with array-type entries?


KenHorse

Recommended Posts

I have a Windows-style ini file that contains entries as such:

 

[Timers]
Timer(1)=50
Timer(2)=30
Timer(3)=20

The entries represent an array  of 3 different timers

Apparently parse_ini_file can't deal with the () format. Is there any way to use this format ini file without having to change how arrays are designated?

Link to comment
Share on other sites

8 minutes ago, KenHorse said:

Apparently parse_ini_file can't deal with the () format

When it comes to it, no part of php uses () format for arrays.

try

[Timers]
Timer[1]=50
Timer[2]=30
Timer[3]=20

with

$timers = parse_ini_file('mytimers.ini', 1);
echo '<pre>', print_r($timers, 1), '</pre>';

giving

Array
(
    [Timers] => Array
        (
            [Timer] => Array
                (
                    [1] => 50
                    [2] => 30
                    [3] => 20
                )

        )

)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.