Re: Working with a config file
| From: | Michael Hulse | Date: | Mon, 20 Feb 2006 22:58:20 +0000 |
| Subject: | Re: Working with a config file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-230772@lists.php.net to get a copy of this message | ||
On Feb 20, 2006, at 2:21 PM, Benjamin Adams wrote:
I want to parse this so I can only call frank or freds data and move id, section, years, etc to varaibles. Can someone give me some helpHere is a function I wrote, I bet it will help you (sorry, not the most readable because I pulled from bigger application I wrote, hopefully you can translate to suit your needs): #### $ini = File to parse. e.g.[ 'rand_01.ini' ] #### You might want to change extension of your config to ".ini", not sure if that will matter. $images = get_ini_file($ini); // Call $get_ini_file() function, put in $images array. ///////////////////////////////////////// function get_ini_file(): ///////////////////////////////////////// Reads ini file for other functions: function get_ini_file($ini) { global $PATH_TO_INI, $DEFAULT_INI_FILE; # if no custom ini file has been specified, use the default: $ini_file = $ini ? $PATH_TO_INI.$ini : $PATH_TO_INI.$DEFAULT_INI_FILE; # read the config file into an array or die trying: $parsed_ini = @parse_ini_file($ini_file, true); if(!$parsed_ini) { die('[ Unable to read ini file! ]'); } else { return $parsed_ini; } }