22-11-2008, 16:49
|
מנהל
|
|
חבר מתאריך: 26.07.08
הודעות: 6,473
|
|
נסה את הקוד הבא, הוא ללא ביטוי רגולרי:
קוד PHP:
write_configs('word', 'Hello World!');
write_configs('time', time());
function write_configs($key, $value)
{
$file = 'cfg.php';
include $file; # Now the $cfg var is available
if (!$cfg) return false;
$cfg[$key] = $value; # Setting new value
// Modifying file content
$output = '';
foreach ($cfg as $key => $val)
$output .= '$cfg[\''.$key.'\'] = '. (is_string($val) ? '\''.addslashes($val).'\'' : $val ).'
'; # creating a new line... so it would look neat
if (! file_put_contents($file,$output))
echo 'Error - Writing to configs file.';
}
|