Forum Moderators: coopster

Message Too Old, No Replies

Editing files and lines

editing files and lines with php

         

xKillswitchx

12:25 am on Jan 20, 2008 (gmt 0)

10+ Year Member



I am looking for a bit of help here. I am reading values from a file and filling a form with default settings (this form will be used to alter CMS config settings, much like Joomla and other CMS use).

I can read from and get values properly, but I used mostly DEFINE to set values for paths, database, etc. Once I submit a form, what would be the best way to go about editing these lines?

Ex.
DEFINE( '__LIVEADMIN__','http://localhost/admin' );
DEFINE( '__PATHADMIN__','C:/wamp/www/admin' );

Once the form is submitted, I would need those values changed. Mainly, all sensitive information is using DEFINE, while small things like site title are using variables.

Thanks for any help you can provide.

venelin13

12:51 am on Jan 20, 2008 (gmt 0)

10+ Year Member



You should use some reqular explation, that matched all of your config/settings variables. Something like this one:

$a = "DEFINE( '__LIVEADMIN__','http://localhost/admin' );";

echo preg_replace("/','(.*?)'/", "', 'http://www.example.org/admin'", $a);

xKillswitchx

1:03 am on Jan 20, 2008 (gmt 0)

10+ Year Member



I dont really understand regular expressions much, havent worked with em yet.

I also decided to use constants instead because throughout the script I dont have to global them or pass them to functions in order to use them.

EDIT - Instead, would it be better to just rewrite all lines? Its only maybe 20 lines or so instead of trying to search and replace?

[edited by: xKillswitchx at 1:29 am (utc) on Jan. 20, 2008]

venelin13

6:54 am on Jan 20, 2008 (gmt 0)

10+ Year Member



RE: Instead, would it be better to just rewrite all lines? Its only maybe 20 lines or so instead of trying to search and replace?

It is realy up to you how to set this functionality. The beauty of PHP is that gives you the freedom to choose from several options. You may use regular expressions, you may open the file and write those lines. The choice is yours.