note 76082 added to function.parse-ini-file

From: Date: Fri, 29 Jun 2007 08:46:46 +0000
Subject: note 76082 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-128073@lists.php.net to get a copy of this message
parse_ini_file can't deal with const which cancate a string. For example, if test.ini file is classPath = ROOT/lib If you: <?php define('ROOT', dirname(__FILE__)); $buf = parse_ini_file('test.ini'); ?> const ROOT would't be parsed. But my version could work find. <?php // array parse_ini_file ( string $filename [, bool $process_sections] ) function parse_ini($filename, $process_sections = false) { function replace_process(& $item, $key, $consts) { $item = str_replace(array_keys($consts), array_values($consts), $item); } $buf = get_defined_constants(true); // PHP version > 5.0 $consts = $buf['user']; $ini = parse_ini_file($filename, $process_sections); array_walk_recursive($ini, 'replace_process', $consts); return $ini; } define('ROOT', '/test'); print_r(parse_ini(dirname(__FILE__).'/test.ini')); ?> ---- Server IP: 212.124.37.9 Probable Submitter: 217.20.117.129 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/76082 Del: integrated -- https://master.php.net/note/delete/76082/integrated Del: useless -- https://master.php.net/note/delete/76082/useless Del: bad code -- https://master.php.net/note/delete/76082/bad+code Del: spam -- https://master.php.net/note/delete/76082/spam Del: non-english -- https://master.php.net/note/delete/76082/non-english Del: in docs -- https://master.php.net/note/delete/76082/in+docs Del: other reasons-- https://master.php.net/note/delete/76082 Reject -- https://master.php.net/note/reject/76082 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128073) next »