note 71545 added to function.parse-ini-file

From: Date: Tue, 05 Dec 2006 14:14:05 +0000
Subject: note 71545 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-120297@lists.php.net to get a copy of this message
I have add to previus function write_ini_file some controls to verify the correct type of item,if the item is null now write the reserved word null and if the item type is boolean write the value true or false. function write_ini_file($path, $assoc_array){ $content = ''; $sections = ''; foreach ($assoc_array as $key => $item) { if (is_array($item)) { $sections .= "\n[{$key}]\n"; foreach ($item as $key2 => $item2) { if(is_null($item2)) { $sections .= "{$key2} = null\n"; } elseif ( (strtoupper(trim($item2))=="TRUE") || (strtoupper(trim($item2))=="FALSE") ) { $sections .= "{$key2} = {$item2}\n"; } elseif (is_bool($item2)) { if ($item2) { $sections .= "{$key2} = true\n"; } else { $sections .= "{$key2} = false\n"; } } elseif (is_numeric($item2) || is_bool($item2)) { $sections .= "{$key2} = {$item2}\n"; } else { $sections .= "{$key2} = \"{$item2}\"\n"; } } } else { if(is_null($item)) { $content .= "{$key} = null\n"; } elseif ( (strtoupper($item)=="TRUE") || (strtoupper($item)=="TRUE") ) { $content .= "{$key} = {$item}\n"; } elseif (is_bool($item)) { if ($item2) { $sections .= "{$key} = true\n"; } else { $sections .= "{$key} = false\n"; } } elseif(is_numeric($item) || is_bool($item)) { $content .= "{$key} = {$item}\n"; } else { $content .= "{$key} = \"{$item}\"\n"; } } } $content .= $sections; if (!$handle = fopen($path, 'w')) { return false; } if (!fwrite($handle, $content)) { return false; } fclose($handle); return true; } ---- Server IP: 80.241.173.254 Probable Submitter: 81.29.232.251 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/71545 Del: integrated -- https://master.php.net/note/delete/71545/integrated Del: useless -- https://master.php.net/note/delete/71545/useless Del: bad code -- https://master.php.net/note/delete/71545/bad+code Del: spam -- https://master.php.net/note/delete/71545/spam Del: non-english -- https://master.php.net/note/delete/71545/non-english Del: in docs -- https://master.php.net/note/delete/71545/in+docs Del: other reasons-- https://master.php.net/note/delete/71545 Reject -- https://master.php.net/note/reject/71545 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120297) next »