Jump to content

Need Help with File


tengkie

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

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.