note 112737 added to function.parse-ini-file
| From: | yicktan | Date: | Thu, 18 Jul 2013 13:45:49 +0000 |
| Subject: | note 112737 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195662@lists.php.net to get a copy of this message | ||
This combo works best for me.
<?php
$inifile = "config.php";
$inivalue = get_parse_ini($inifile);
print_r($inivalue);
$inivalue['config']['length']=6;
put_ini_file("config.php", $inivalue, $i = 0);
function get_parse_ini($file)
{
// if cannot open file, return false
if (!is_file($file))
return false;
$ini = file($file);
// to hold the categories, and within them the entries
$cats = array();
foreach ($ini as $i) {
if (@preg_match('/\[(.+)\]/', $i, $matches)) {
$last = $matches[1];
} elseif (@preg_match('/(.+)=(.+)/', $i, $matches)) {
$cats[$last][trim($matches[1])] = trim($matches[2]);
}
}
return $cats;
}
function put_ini_file($file, $array, $i = 0){
$str="";
foreach ($array as $k => $v){
if (is_array($v)){
$str.=str_repeat(" ",$i*2)."[$k]\r\n";
$str.=put_ini_file("",$v, $i+1);
}else
$str.=str_repeat(" ",$i*2)."$k = $v\r\n";
}
$phpstr = "<?PHP\r\n/*\r\n".$str."*/\r\n?>";
if($file)
return file_put_contents($file,$phpstr);
else
return $str;
}
?>
here is the config.php file
<?php
/*
;Commented line start with ';'
[config]
admin = root
pass = pass
email = social@facebook.com
length = 4
block = 4
seperation = -
*/
?>
Test it out yourself
----
Server IP: 69.147.83.199
Probable Submitter: 125.92.118.15
----
Manual Page -- http://php.net/manual/en/function.parse-ini-file.php
Edit -- https://master.php.net/note/edit/112737
Del: integrated -- https://master.php.net/note/delete/112737/integrated
Del: useless -- https://master.php.net/note/delete/112737/useless
Del: bad code -- https://master.php.net/note/delete/112737/bad+code
Del: spam -- https://master.php.net/note/delete/112737/spam
Del: non-english -- https://master.php.net/note/delete/112737/non-english
Del: in docs -- https://master.php.net/note/delete/112737/in+docs
Del: other reasons-- https://master.php.net/note/delete/112737
Reject -- https://master.php.net/note/reject/112737
Search -- https://master.php.net/manage/user-notes.php