Click to See Complete Forum and Search --> : please help me......urgent..


eina_227
11-02-2004, 09:33 PM
-----------------------------------------------------------
//file name->pref.conf.php
<?php
$test['type']="mysql";
$test['data']="not yet received";
?>
---------------------------------------------------------
//file name-> conf.php

<?php
include "pref.conf.php";

?>


<form action="conf.php" method="post">
type: <input type="text" name="type" value="<?php echo $test['type'];?>"><br />
data: <input type="text" name="data" value="<?php echo $test['data'];?>"><br />

<input type="submit" name="submit" value="Submit" />

</form>
-----------------------------------------------------------------------

my problem is how to change data at the pref.conf.php file using the html form .i have no idea how to apply the ( $test['type']=$_request['type'] ) to the conf.php file..please help me....

Jona
11-03-2004, 12:33 AM
<?php
// config.php
$test = array();

$test['type'] = "not mysql";
$test['data'] = "some data";
?>



<?php
$file = file_get_contents("config.php");

function newConfig($var, $val, $d){
return preg_replace("/test\\['$var'\\]\\s*=\\s*\\"(.*)\\"/i", "test['$var'] = \\"$val\\"", $d);
}
$newData = newConfig('type', 'not mysql', $file);
$newData = newConfig('data', 'some data', $newData);

$fp = fopen("config.php", "w");
fwrite($fp, $newData);
fclose($fp);
?>