note 38641 added to function.file

From: Date: Wed, 31 Dec 2003 14:39:07 +0000
Subject: note 38641 added to function.file
Groups: php.notes 
Request: Send a blank email to php-notes+get-62725@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.file.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38641 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38641&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38641&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62725) next »