php-general Digest 12 Nov 2010 11:29:00 -0000 Issue 7034

Topics (messages 309460 through 309472):

Re: parse_ini_file() seems to be broken in PHP 5.2.4-2ubuntu5.12
        309460 by: Daevid Vincent

Re: use of ini vs include file for configuration
        309461 by: Daevid Vincent
        309462 by: Daevid Vincent
        309467 by: Ashley Sheridan

Open Source PHP/ mySQL Project Management
        309463 by: Don Wieland
        309465 by: Andre Polykanine
        309468 by: Jonathan Tapicer
        309469 by: Andre Polykanine
        309470 by: Ken Guest
        309471 by: Irimia, Şuleapă

Re: How do I convert the string "E_ALL & ~E_NOTICE" to the decimal equivalent 
6135?
        309464 by: Daevid Vincent
        309472 by: Ford, Mike

Re: a better ini parser WAS: parse_ini_file() seems to be broken in PHP 
5.2.4-2ubuntu5.12
        309466 by: Daevid Vincent

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
 

> -----Original Message-----
> From: Tamara Temple [mailto:[email protected]] 
> Sent: Thursday, November 11, 2010 1:09 AM
> To: Daevid Vincent
> Cc: [email protected]
> Subject: Re: [PHP] parse_ini_file() seems to be broken in PHP 
> 5.2.4-2ubuntu5.12
> 
> 
> On Nov 10, 2010, at 8:08 PM, Daevid Vincent wrote:
> 
> > http://php.net/manual/en/function.parse-ini-file.php
> >
> > Why doesn't PHP parse the 'null', 'true', 'false', etc into their  
> > proper
> > equivalents? What's worse is that it does this mangling of my RAW  
> > values to
> > be strings and sets them to "1" !!! WTF good does that do me?!
> >
> >
> > Here is my test.ini file:
> > 
> --------------------------------------------------------------
> -------------
> > ---------------------------
> > [examples]                                  ; this is a section
> >                                            ; this is a comment line
> > log_level = E_ALL & ~E_NOTICE
> > 1 = intkey                                  ; this is a int key
> > nullvalue = null                            ; this is NULL
> > truebool = true                             ; this is boolean (TRUE)
> > falsebool = false                           ; this is 
> boolean (FALSE)
> > intvalue = -1                               ; this is a integer (-1)
> > floatvalue = +1.4E-3                        ; this is a 
> float (0.0014)
> > stringvalue = Hello World                   ; this is a unquoted  
> > string
> > quoted = "Hello World"                      ; this is a 
> quoted string
> > apostrophed = 'Hello World'                 ; this is a 
> apostrophed  
> > string
> > quoted escaped = "it work's \"fine\"!"      ; this is a quoted  
> > string with
> > escaped quotes
> > apostrophed escaped = 'it work\'s "fine"!'  ; this is a 
> apostrophed  
> > string
> > with escaped apostrophes
> > 
> --------------------------------------------------------------
> -------------
> > ---------------------------
> >
> > Here is my test.php page:
> > 
> --------------------------------------------------------------
> -------------
> > ---------------------------
> > <?php
> >     var_dump(parse_ini_file('./test.ini', true));
> > ?>
> > 
> --------------------------------------------------------------
> -------------
> > ---------------------------
> >
> > Here is the output:
> > 
> --------------------------------------------------------------
> -------------
> > ---------------------------
> > array
> >  'examples' =>
> >    array
> >      'log_level' => string '6135' (length=4)
> >      1 => string 'intkey' (length=6)
> >      'nullvalue' => string '' (length=0)
> >      'truebool' => string '1' (length=1)
> >      'falsebool' => string '' (length=0)
> >      'intvalue' => string '-1' (length=2)
> >      'floatvalue' => string '+1.4E-3' (length=7)
> >      'stringvalue' => string 'Hello World' (length=11)
> >      'quoted' => string 'Hello World' (length=11)
> >      'apostrophed' => string ''Hello World'' (length=13)
> >      'quoted escaped' => string 'it work's \fine\!' (length=17)
> >      'apostrophed escaped' => string ''it work\'sfine' (length=15)
> > 
> --------------------------------------------------------------
> -------------
> > ---------------------------
> >
> >
> >
> > develo...@mypse:~$ php -v
> > PHP 5.2.4-2ubuntu5.12 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep  
> > 20 2010
> > 13:18:10)
> > Copyright (c) 1997-2007 The PHP Group
> > Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
> >    with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
> 
> Maybe I'm missing something, but i thought that's what the constants  
> evaluated to....

In a "sloppy" way that is accurate, but not sufficient for my needs.

If ($nullvalue) ....
If ($truebool) ...

But to be more accurate, 

$nullvalue != is_null($nullvalue)
$truebool != is_bool($truebool) 
$truebool !== TRUE 
Etc...

There are subtle but significant differences


--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Tamara Temple [mailto:[email protected]] 
> Sent: Thursday, November 11, 2010 11:04 AM
> To: PHP General
> Subject: [PHP] use of ini vs include file for configuration
> 
> I'm curious what the lists' opinions are regarding the use of 
> an .ini  
> file versus an include configuration file in PHP code are?
> 
> I can see uses for either (or both).
> 
> To me, it seems that an .ini file would be ideal in the case 
> where you  
> want to allow a simpler interface for people installing your app to  
> configure things that need configuring, and an included PHP code  
> configuration file for things you don't necessarily want the average  
> installer to change.
> 
> What do you think?
> 
> Tamara

We used config.inc.php for the past few years, but as our project is grown
and we have several other departments developing portions in several
different languages (not JUST PHP) but all wanting to share resources such
as database connection information, pathing, email addresses (for error
reporting, notifications, etc.), memcache servers, etc. using a PHP file is
not an option. It can be a shim however and that's what I've done over the
past few days is to parse the .ini and populate the same config.inc.php
file with said values so that all the code continues to work. Plus it
allows for easy populating in a programatic way if you name your variables
right and organize things.


--- End Message ---
--- Begin Message ---
 

> -----Original Message-----
> From: Ashley Sheridan [mailto:[email protected]] 
> Sent: Thursday, November 11, 2010 11:46 AM
> To: Jo?o C?ndido de Souza Neto
> Cc: [email protected]
> Subject: Re: [PHP] Re: use of ini vs include file for configuration
> 
> On Thu, 2010-11-11 at 17:16 -0200, Jo?o C?ndido de Souza Neto wrote:
> 
> > Agreed.
> > 
> > -- 
> > Joo Cndido de Souza Neto
> > 
> > "Tamara Temple" <[email protected]> escreveu na mensagem 
> > news:[email protected]...
> > > I'm curious what the lists' opinions are regarding the 
> use of an .ini 
> > > file versus an include configuration file in PHP code are?
> > >
> > > I can see uses for either (or both).
> > >
> > > To me, it seems that an .ini file would be ideal in the 
> case where you 
> > > want to allow a simpler interface for people installing 
> your app to 
> > > configure things that need configuring, and an included PHP code 
> > > configuration file for things you don't necessarily want 
> the average 
> > > installer to change.
> > >
> > > What do you think?
> > >
> > > Tamara
> > > 
> > 
> > 
> > 
> 
> 
> There are potential security concerns involved too. An .ini 
> file will be
> output as plain text by default by the web server if 
> requested by a user
> agent unless it is protected somehow (by a .htaccess file for example)
> or it is outside of document root for the server. A PHP file on the
> other hand will be parsed, so won't output it's variables.
> 
> It's all too easy to forget to protect an ini file from this sort of
> thing, whereas if you've written a website in PHP, it becomes fairly
> evident if your web server isn't configured for PHP without testing
> specifically for it!

Why would you put your configuration file in a ../htdocs folder? That's
just poor design.

Just as your classes and include files are OUTSIDE your document root, so
must your config file be.

Plus it's trivial to secure a .ini with a .htaccess or other apache method.


--- End Message ---
--- Begin Message ---
On Thu, 2010-11-11 at 14:21 -0800, Daevid Vincent wrote:

> 
> > -----Original Message-----
> > From: Ashley Sheridan [mailto:[email protected]] 
> > Sent: Thursday, November 11, 2010 11:46 AM
> > To: Jo?o C?ndido de Souza Neto
> > Cc: [email protected]
> > Subject: Re: [PHP] Re: use of ini vs include file for configuration
> > 
> > On Thu, 2010-11-11 at 17:16 -0200, Jo?o C?ndido de Souza Neto wrote:
> > 
> > > Agreed.
> > > 
> > > -- 
> > > Joo Cndido de Souza Neto
> > > 
> > > "Tamara Temple" <[email protected]> escreveu na mensagem 
> > > news:[email protected]...
> > > > I'm curious what the lists' opinions are regarding the 
> > use of an .ini 
> > > > file versus an include configuration file in PHP code are?
> > > >
> > > > I can see uses for either (or both).
> > > >
> > > > To me, it seems that an .ini file would be ideal in the 
> > case where you 
> > > > want to allow a simpler interface for people installing 
> > your app to 
> > > > configure things that need configuring, and an included PHP code 
> > > > configuration file for things you don't necessarily want 
> > the average 
> > > > installer to change.
> > > >
> > > > What do you think?
> > > >
> > > > Tamara
> > > > 
> > > 
> > > 
> > > 
> > 
> > 
> > There are potential security concerns involved too. An .ini 
> > file will be
> > output as plain text by default by the web server if 
> > requested by a user
> > agent unless it is protected somehow (by a .htaccess file for example)
> > or it is outside of document root for the server. A PHP file on the
> > other hand will be parsed, so won't output it's variables.
> > 
> > It's all too easy to forget to protect an ini file from this sort of
> > thing, whereas if you've written a website in PHP, it becomes fairly
> > evident if your web server isn't configured for PHP without testing
> > specifically for it!
> 
> Why would you put your configuration file in a ../htdocs folder? That's
> just poor design.
> 
> Just as your classes and include files are OUTSIDE your document root, so
> must your config file be.
> 
> Plus it's trivial to secure a .ini with a .htaccess or other apache method.
> 
> 


Tell that to the developers of all the big names out there, phpMyAdmin,
phpBB, CodeIgniter, et al. All of them, for ease of use, put all the
config files in the htdocs directory by default, presumably so that they
don't lock out those people who can only get hosting that does not allow
much more than basic configuration.

It might be poor design, but it's just the way things are, and if you're
working with such hosting, it's worth bearing in mind what your options
are. I did mention specifically about putting the config files outside
of document root, but that's not always possible in every case.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Hi gang,

I am looking into Project Management apps for my projects. Any suggestions:

I am interested in tracking Projects, Milestones, Tickets, Files, Discussions, Documents, Time Tracking, etc... Also, would like to have the system have robust email integration Reminders, Email Ticket echos (where a user can reply it will post back into the PM system and echo back email to assigned users - with file attachments)

Suggestions? Thanks!

Don

--- End Message ---
--- Begin Message ---
Hello Don,

I would suggest Trac. It is written in Python, however I haven't seen
anything better for a while.
-- 
With best regards from Ukraine,
Andre
Skype: Francophile
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

----- Original message -----
From: Don Wieland <[email protected]>
To: [email protected] <[email protected]>
Date: Friday, November 12, 2010, 12:23:11 AM
Subject: [PHP] Open Source PHP/ mySQL Project Management

Hi gang,

I am looking into Project Management apps for my projects. Any  
suggestions:

I am interested in tracking Projects, Milestones, Tickets, Files,  
Discussions, Documents, Time Tracking, etc... Also, would like to have  
the system have robust email integration Reminders, Email Ticket echos  
(where a user can reply it will post back into the PM system and echo  
back email to assigned users - with file attachments)

Suggestions? Thanks!

Don

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Hi,

I don't know if it meets all of the features you enumerated but Mantis
(http://www.mantisbt.org/) is very good, and it is PHP+MySQL (or
Postgres, or MSSQL).

Jonathan

On Thu, Nov 11, 2010 at 7:23 PM, Don Wieland <[email protected]> wrote:
> Hi gang,
>
> I am looking into Project Management apps for my projects. Any suggestions:
>
> I am interested in tracking Projects, Milestones, Tickets, Files,
> Discussions, Documents, Time Tracking, etc... Also, would like to have the
> system have robust email integration Reminders, Email Ticket echos (where a
> user can reply it will post back into the PM system and echo back email to
> assigned users - with file attachments)
>
> Suggestions? Thanks!
>
> Don
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hello Jonathan,

I tried to use Mantis, however it didn't send e-mails properly so I
gave up.
-- 
With best regards from Ukraine,
Andre
Skype: Francophile
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

----- Original message -----
From: Jonathan Tapicer <[email protected]>
To: Don Wieland <[email protected]>
Date: Friday, November 12, 2010, 3:00:32 AM
Subject: [PHP] Open Source PHP/ mySQL Project Management

Hi,

I don't know if it meets all of the features you enumerated but Mantis
(http://www.mantisbt.org/) is very good, and it is PHP+MySQL (or
Postgres, or MSSQL).

Jonathan

On Thu, Nov 11, 2010 at 7:23 PM, Don Wieland <[email protected]> wrote:
> Hi gang,
>
> I am looking into Project Management apps for my projects. Any suggestions:
>
> I am interested in tracking Projects, Milestones, Tickets, Files,
> Discussions, Documents, Time Tracking, etc... Also, would like to have the
> system have robust email integration Reminders, Email Ticket echos (where a
> user can reply it will post back into the PM system and echo back email to
> assigned users - with file attachments)
>
> Suggestions? Thanks!
>
> Don
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
With the exception of some work-mandated systems such as fogbugz, I've used
mantis successfully for quite a long time.

On Fri, Nov 12, 2010 at 1:09 AM, Andre Polykanine <[email protected]> wrote:

> Hello Jonathan,
>
> I tried to use Mantis, however it didn't send e-mails properly so I
> gave up.
> --
> With best regards from Ukraine,
> Andre
> Skype: Francophile
> Twitter: http://twitter.com/m_elensule
> Facebook: http://facebook.com/menelion
>
> ----- Original message -----
> From: Jonathan Tapicer <[email protected]>
> To: Don Wieland <[email protected]>
> Date: Friday, November 12, 2010, 3:00:32 AM
> Subject: [PHP] Open Source PHP/ mySQL Project Management
>
> Hi,
>
> I don't know if it meets all of the features you enumerated but Mantis
> (http://www.mantisbt.org/) is very good, and it is PHP+MySQL (or
> Postgres, or MSSQL).
>
> Jonathan
>
> On Thu, Nov 11, 2010 at 7:23 PM, Don Wieland <[email protected]>
> wrote:
> > Hi gang,
> >
> > I am looking into Project Management apps for my projects. Any
> suggestions:
> >
> > I am interested in tracking Projects, Milestones, Tickets, Files,
> > Discussions, Documents, Time Tracking, etc... Also, would like to have
> the
> > system have robust email integration Reminders, Email Ticket echos (where
> a
> > user can reply it will post back into the PM system and echo back email
> to
> > assigned users - with file attachments)
> >
> > Suggestions? Thanks!
> >
> > Don
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
http://blogs.linux.ie/kenguest/

--- End Message ---
--- Begin Message ---
Redmine is (I think) one of the best out there. It is written in ruby
and does have all you need + some more.

Cheers!

On Fri, Nov 12, 2010 at 12:23 AM, Don Wieland <[email protected]> wrote:
> Hi gang,
>
> I am looking into Project Management apps for my projects. Any suggestions:
>
> I am interested in tracking Projects, Milestones, Tickets, Files,
> Discussions, Documents, Time Tracking, etc... Also, would like to have the
> system have robust email integration Reminders, Email Ticket echos (where a
> user can reply it will post back into the PM system and echo back email to
> assigned users - with file attachments)
>
> Suggestions? Thanks!
>
> Don
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
 

> -----Original Message-----
> From: Ford, Mike [mailto:[email protected]] 
> Sent: Thursday, November 11, 2010 12:58 AM
> To: [email protected]
> Subject: RE: [PHP] How do I convert the string "E_ALL & 
> ~E_NOTICE" to the decimal equivalent 6135?
> 
> > -----Original Message-----
> > From: Daevid Vincent [mailto:[email protected]]
> > Sent: 11 November 2010 04:06
> > To: [email protected]
> > 
> > We're trying to move all of our configuration files for our
> > DEV/TEST/PROD
> > and various python scripts and such that all need the same DB
> > connection
> > parameters and pathing information to a common and simple config.ini
> > file
> > they all can share across languages.
> > 
> > One snag I ran into is this:
> > 
> > [dart]
> > relative_url        = /dart2
> > absolute_path       = /home/www/dart2
> > log_level           = E_ALL & ~E_NOTICE
> > 
> > But when I read it in from the file, it's a string (of course)
> 
> That's odd -- parse_ini_file() should definitely translate 
> those constants!
> It certainly works on my v5.2.5 installation.
> 
> Cheers!
> 
> Mike

You assume I'm using that busted-ass "parse_ini_file()" function. ;-)

See previous emails as to why that's a useless option for me.

I wrote a much better parser which I'll post in another email.


--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Daevid Vincent [mailto:[email protected]]
> Sent: 11 November 2010 22:23
> To: [email protected]
> 
> > -----Original Message-----
> > From: Ford, Mike [mailto:[email protected]]
> > Sent: Thursday, November 11, 2010 12:58 AM
> > To: [email protected]
> > Subject: RE: [PHP] How do I convert the string "E_ALL &
> > ~E_NOTICE" to the decimal equivalent 6135?
> >
> > > -----Original Message-----
> > > From: Daevid Vincent [mailto:[email protected]]
> > > Sent: 11 November 2010 04:06
> > > To: [email protected]
> > >
> > > We're trying to move all of our configuration files for our
> > > DEV/TEST/PROD
> > > and various python scripts and such that all need the same DB
> > > connection
> > > parameters and pathing information to a common and simple
> config.ini
> > > file
> > > they all can share across languages.
> > >
> > > One snag I ran into is this:
> > >
> > > [dart]
> > > relative_url      = /dart2
> > > absolute_path     = /home/www/dart2
> > > log_level         = E_ALL & ~E_NOTICE
> > >
> > > But when I read it in from the file, it's a string (of course)
> >
> > That's odd -- parse_ini_file() should definitely translate
> > those constants!
> > It certainly works on my v5.2.5 installation.
> >
> > Cheers!
> >
> > Mike
> 
> You assume I'm using that busted-ass "parse_ini_file()" function. ;-
> )
> 
> See previous emails as to why that's a useless option for me.
> 
> I wrote a much better parser which I'll post in another email.

Ah, I see. I don't believe you mentioned that in your original query.
In that case, your only option probably is eval - something like:

    eval("\$log_level_int = {$log_level_string}");

or:

    $log_level_int = eval("return {$log_level_string}");

Cheers!

Mike

 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507 City Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: [email protected] 
Tel: +44 113 812 4730






To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
Since the default ini parser is pretty much useless because it doesn't
convert null/true/false values, nor convert integers/numbers, nor handle
all the ; comment styles (inline for example), nor trim extra white space,
and the list goes on and on...

I wrote a better one -- here's the first stab at it. I'm sure I'll improve
it as needed, but you're free to use as you like and hopefully it will save
someone else the pain and wasted effort on parse_ini_file():

<?php
/**
 * INI file parser
 *
 * @author              Daevid Vincent <[email protected]>
 * @date                Created: 2010-11-09
 */

class IniParser
{
        private $file;
        public  $ini_array;

        /**
        * Constructor and acts as a singleton for the same $file
        *
        * @access       public
        * @return       object
        * @param        string $file the .ini file to load with full path
        * @param        boolean $process_sections (true) return a
multi-hash broken down by sections
        * @param        boolean $explode (false) split . keys into
sub-array elements
        * @author       Daevid Vincent [[email protected]]
        * @date         2010-11-09
        */
        function __construct($file, $process_sections=true, $explode=false)
        {
                if ($_SESSION['INI_PARSER'][$file])
                {
                        //echo "using pre-made version<br>";
                        return $_SESSION['INI_PARSER'][$file];
                }

                $this->file = $file;

                //[dv] okay so parse_ini_file() is basically a USELESS POS
                //         not only does it NOT convert true/false/null to
proper equivalents, but it mangles the values to be "1"(strings)
                //         verified with 5.2.4 to 5.3.3, so not much hope
for using this function natively
                //$this->ini_array =
parse_ini_file($file,$process_sections);
                $this->ini_array = $this->read_ini_file($file);
                $this->transpose_ini();

                if ($explode) $this->explode_ini();

                //TODO: handle the 'embrace extend' functionality that Zend
Framework provides with the [section : section] format

                //echo "using new version<br>";
                $_SESSION['INI_PARSER'][$file] = $this;
                return $this;
        }

        private function read_ini_file($file)
        {
            $handle = @fopen($file, "r");
            if (!$handle) throw new Exception('Cannot open INI file
'.$file);
            $contents = @fread($handle, filesize($file));
            if (!$contents) throw new Exception('Cannot read INI file
'.$file);

            $section = '';
            $contents = split("\n", trim($contents));
            foreach ($contents as $k => $line)
            {
                $line = trim($line);
                if (!$line) continue;
                if (in_array($line[0], array(';','#'))) continue;

                if ($line[0] == "[")
            {
                preg_match('/\[(.*)\]/', $line, $pmatches);
                $section = $pmatches[1];
            }
            else
            {
                $keyval = explode('=', $line);
                $tmp = explode(';',$keyval[1]);
                $mykey = trim($keyval[0]);
                $myval = trim($tmp[0]);

                if (substr($mykey, -2) == '[]')  //check for arrays
                        $ini_file[$section][substr($mykey, 0, -2)][] =
$myval;
                else
                        $ini_file[$section][$mykey] = $myval;
            }
            }

            @fclose($handle);
            return $ini_file;
        }

        private function transpose_ini()
        {
                foreach($this->ini_array as $heading => &$key_vals)
                {
                        foreach ($key_vals as $k => &$v)
                        {
                                //echo "$k => $v<br>\n";
                                if (is_numeric($v))
                                {
                                        $i = intval($v);
                                        if ($i == $v) $v = $i;
                                }
                                else
                                switch (strtolower($v))
                                {
                                        case 'true':  $v = true; break;
                                        case 'false': $v = false; break;
                                        case 'null':  $v = null; break;
                                }
                        }
                }
        }

        /*
         * not used currently, but took a while to get this working so keep
for future reference/use
        public function explode_ini()
        {
                $ini_array = array();

                foreach($this->ini_array as $heading => $key_vals)
                {
                        foreach ($key_vals as $k => $v)
                        {
                                $path = 'ini_array[\''.$heading.'\']';
                                $subsection = explode('.', $k);
                                foreach ($subsection as $ss) $path .=
'[\''.$ss.'\']';
                                if (is_string($v)) $path = '$'.$path.' =
\''.$v.'\';'; else      $path = '$'.$path.' = '.$v.';';
                                eval($path); //it's not elegant but it
works!
                        }
                }

                $this->ini_array = $ini_array;
        }
        */

        public function get_value($section, $key)
        {
                //echo "$section / $key =
".$this->ini_array[$section][$key]."<br>\n";
                if (is_string($key))
                {
                        return $this->ini_array[$section][$key];
                }

                //TODO: else it's an (exploded) nested array so traverse to
find the value
        }

        public function __toString()
        {
                var_dump($this->ini_array);
                return '';
        }
}
?>



$mypath = dirname(__FILE__);
require_once $mypath.'/classes/IniParser.class.php';
try
{
        $config_ini = new IniParser($mypath.'/config.ini', true);
}
catch (Exception $e)
{
        exit('Caught Exception parsing ini
file.<br>'.$e->getMessage()."\n");
}
if (!is_array($config_ini->ini_array)) exit('No config.ini loaded. Can not
proceed.');



$myinioption = $config_ini->get_value('some_section',
'some.ini.config.option.here');


--- End Message ---

Reply via email to