note 38641 deleted from function.file by tularis
| From: | tularis@php.net | Date: | Fri, 30 Nov 2007 12:17:07 +0000 |
| Subject: | note 38641 deleted from function.file by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-132688@lists.php.net to get a copy of this message | ||
Note Submitter: mvanbeek at supporting-role dot co dot uk
----
I needed a cross platform config file for a project using both perl and php, so I used the perl
script in the Perl Cookbook, and wrote the following PHP script. This going in an include file that
all the PHP files reference, so the only thing that needs to be do for set up, is to set the
location of the config file.
$filename = "/opt/ssis/includes/ssis-config";
$config = file($filename);
reset ($config);
foreach ($config as $line)
{
if ( $line == "" ) next($config); # Ignore blankline
elseif ( $line == "\n" ) next($config); # Ignore newline
elseif ( strstr($line,"#")) next($config); # Ignore comments
else
{
$line = rtrim($line); # Get rid of newline characters
$line = ltrim($line); # Get rid of any leading spaces
$value = preg_split("/\s*=\s*/", $line, 2); # split by "=" and
removing blank space either side of it.
${Settings}["$value[0]"] = $value[1]; # Create a new array with all the values.
}
}
I am sure there is a neater way of doing it, but all the Config libaries floating arround seemed
very complicated. All the config file needs is a series of lines ( key = value ) in plain text.