echoCarlos Posted June 9, 2011 Share Posted June 9, 2011 Hi guys I'm tying to update the config.inc.php with the database info from the install.php Install.php $string = '<?php $db_host = "'. $_POST["host"]. '"; $db_user = "'. $_POST["username"]. '"; $db_pass = "'. $_POST["password"]. '"; ?>'; $fp = fopen("config.inc.php", "a"); fwrite($fp, $string); fclose($fp); config.inc.php $db_host = ''; $db_user = ''; $db_pass = ''; // connect to the server $con = mysql_connect($db_host,$db_user,$db_pass) or die('Failed to connect to the server'); // connect to the database $db = mysql_select_db('marketplace') or die('Failed to connect to the database'); can someone help me on how id do this Link to comment https://forums.phpfreaks.com/topic/238842-fwrite-preg_replace/ Share on other sites More sharing options...
mgoodman Posted June 9, 2011 Share Posted June 9, 2011 Well as your title suggests you've figured out that you need to use preg_replace. Try this: $contents = file_get_contents('config.inc.php'); $regex = array( 'expressions' => array( '/\$db_host = \'\';/', '/\$db_user = \'\';/', '/\$db_pass = \'\';/' ), 'data' => array( '$db_host = \'' . $_POST['host'] . '\';', '$db_user = \'' . $_POST['username'] . '\';', '$db_pass = \'' . $_POST['password'] . '\';' ) ); $contents = preg_replace($regex['expressions'], $regex['data'], $contents); // fwrite $contents back to config.inc.php Link to comment https://forums.phpfreaks.com/topic/238842-fwrite-preg_replace/#findComment-1227272 Share on other sites More sharing options...
echoCarlos Posted June 9, 2011 Author Share Posted June 9, 2011 Just woken up, thank you very much for your reply mate I'll try that right away after I've had my coffee Link to comment https://forums.phpfreaks.com/topic/238842-fwrite-preg_replace/#findComment-1227351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.