Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/154651-need-help-with-file/
Share on other sites

<?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);

Link to comment
https://forums.phpfreaks.com/topic/154651-need-help-with-file/#findComment-813239
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.