icekat83 Posted December 5, 2010 Share Posted December 5, 2010 Hi, I have a file which contains settings for a user. Similar to wordpress except simpler like setting a default email for error messages or something. The idea is that it's used as an installation script for web-ware where someone fills in a form with their database details, my script will hard-code them into the settings file and then delete itself. I'll admit I did get the idea from wordpress. Only the way it's coded currently requires a certain combination of characters at the end and seems really messy. The script looks like this (and does work): $endpos = strpos ( $contents, '"; //replace with name//', $startpos); The settings file looks like this: $hard_name = "Smith"; //replace with name// As you can see I use the comment in the settings file, which follows what I'm actually changing, to find the end of the variable. I am sure there must be a better way of doing things but don't know what. It just seems really inefficient because if the comment is removed the script breaks. Any info and tips would be much appreciated. IceKat Quote Link to comment https://forums.phpfreaks.com/topic/220706-altering-actual-file-contents/ Share on other sites More sharing options...
.josh Posted December 5, 2010 Share Posted December 5, 2010 sooo... why can't your "settings" file be a regular php file to be included, and the variable can be set like a normal variable? config.php $someVar = "blah"; file.php include('config.php'); echo $someVar; Quote Link to comment https://forums.phpfreaks.com/topic/220706-altering-actual-file-contents/#findComment-1143116 Share on other sites More sharing options...
laffin Posted December 5, 2010 Share Posted December 5, 2010 I've done something like that a long long long time ago, it was to administer the installation settings and maintain them. I took the path that CrayonViolent is suggesting, by storing the variables as a php script to be included, the other option is to store them as serialized data, but i wouldn't recommend saving the serialized data as just a file, a php file ok <?php $sample=array( 'name'=>'John Doe', 'password'=>'JaneDoe' ); $data='<?php $config=unserialize(\''. serialize($sample) .'\'); ?>'; file_put_contents('config.php',$data); ?> Quote Link to comment https://forums.phpfreaks.com/topic/220706-altering-actual-file-contents/#findComment-1143129 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.