tengkie Posted April 18, 2009 Share Posted April 18, 2009 Hi, i do really need help with file.. Let say i have a config.php: <?//config.php $firstline = [XCONFIG_FIRST]; $secondline = [XCONFIG_SECOND]; $thirdline = [XCONFIG_THIRD]; ?> And I have other php script (this contains forms, called it replace.php) which I will use it for change all values from config.php. This script will change the [XCONFIG_FIRST]; [XCONFIG_SECOND] & [XCONFIG_THIRD] with other value that I set from replace.php. <!-- replace.php --> <form method="post" action="something.php"> XConfig First : <input type="text" name="xcon_first" value=""><br/> XConfig Second : <input type="text" name="xcon_second" value=""><br/> XConfig Third : <input type="text" name="xcon_third" value=""><br/> <input type="submit" value="Replace All"> </form> All values submitted from replace.php will replace [XCONFIG_FIRST] and so on from config.php Is there any ways to do it? Thank you so much for your kind help. Quote Link to comment https://forums.phpfreaks.com/topic/154651-need-help-with-file/ Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 <?php //config.php $firstline = '[XCONFIG_FIRST]'; $secondline = '[XCONFIG_SECOND]'; $thirdline = '[XCONFIG_THIRD]'; // something.php $search = array(); $replace = array(); $search[] = $firstline; $replace[] = (isset($_POST['xcon_first']) ? $_POST['xcon_first'] : ''); $search[] = $secondline; $replace[] = (isset($_POST['xcon_second']) ? $_POST['xcon_second'] : ''); $search[] = $thirdline; $replace[] = (isset($_POST['xcon_third']) ? $_POST['xcon_third'] : ''); $newText = str_replace($search, $replace, $oldText); Quote Link to comment https://forums.phpfreaks.com/topic/154651-need-help-with-file/#findComment-813239 Share on other sites More sharing options...
tengkie Posted April 18, 2009 Author Share Posted April 18, 2009 thanks for the reply.. I'll try this code... Quote Link to comment https://forums.phpfreaks.com/topic/154651-need-help-with-file/#findComment-813242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.