Jump to content

write variables string to another file


echoCarlos

Recommended Posts

Hi guys, I have a php file called install.php and the user submits there host details, the thing is i also want to write those details to these define functions in includes/config.php with the content

 

define('DB_HOST', 'change1');
define('DB_USER', 'change2');
define('DB_PASS', 'change3');

 

and overwrite change1 with host and user and pass

 

how could this be done

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/238830-write-variables-string-to-another-file/
Share on other sites

if you have the 'blank' file saved already, use the file object to read the file into a variable, and use str_replace() to change it.

$filetext = str_replace('change1','localhost',$filetext);

 

assume i have read the file contents of the example you gave, into $filetext, I then ask it to look for 'change1' in that string and replace that with 'localhost', and pass it back to the $filetext. i would then write that variable to the file and save file .

Thanks for the help but i managed to find something which did the trick on Google will post here incase anyone needs it.

 


<?php



$string = '<?php 

$dbhost = "'. $_POST["dbhost"]. '";

$dbuname = "'. $_POST["dbuname"]. '";

$dbpass = "'. $_POST["dbpass"]. '";

$dbname = "'. $_POST["dbname"]. '";

$prefix = "'. $_POST["prefix"]. '";

$user_prefix = "'. $_POST["user_prefix"]. '";

$dbtype = "'. $_POST["dbtype"]. '";

?>';



$fp = fopen("config.php", "w");

fwrite($fp, $string);

fclose($fp);



?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.