Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flat file config file 1

Status
Not open for further replies.

bobbiedigital

Programmer
Sep 18, 2004
83
0
0
AU
Hi im making a config file called siteconfig.php for a website within this file i have common variables used through out the site. the variables in the files are as such

$siteName = "Some ones website";
$siteOwner = "Joe bloggs";

Im trying to get these editable via a form, there is one way its possible to do it is opening the file and creating a regular expression, but are there other ways???

Possibly creating all the variables as an array, then create a function to return the array when its needed.

Are there any other ways of doing this and editing the variables????

Thank you for your time

Bobbie
 
Why not use some DBMS and put the values there and update them?


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Would doing that mean to access the data i would keep having to create sql statements each time i need the data? if stored in a flatfile wouldnt it be possible to just include the file and then use the variables through out the site??? for example just use include("siteconfig.php"); at the top of the page the i will be able to use the variables in that file for that page?
but in saying that i spose my main concern is efficiency, is the database method more efficient and is it better coding practice?
I like the simplicity of a flat file, but if its too difficult to update then the database solution maybe useful.
 
You can do that on a flat file, but you would have to set the file have each variable on one line, and then once you have read the file into a string using fopen and fread. explode the string into the lines, and then edit the values for the variables, re-implode the array into a string, and write the file back.


It can be done, but it will take more code, to accomplish if there many variables inside the config file.

Of course if the creation of the file is only meant to happen once, then you can avoid the whole reading and exploding process, and just create the file on the fly. remembering to add the <?PHP and ?> brackets at the beginning and end of the file, so it can be parsed when its included.



something like:

Code:
[green]use single quotes so variable names don;t get interpolated, but are instead treated as strings.[/green]
$configfilecontents='[red]<?PHP \n $variablename="variablevalue"; \n $othervariablename="othervariablevalue"; \n ?>[/red]';

Then write the string to the file.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Including a flat file may be convinient in accessing the variables but may not be efficient to edit them using ui/form.
If you are not using some DBMS in your appliocation, then don't use it solely for this purpose and the way suggested by vacunita is recommended.


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Ok thanks for the repsonses i think i might go with vacunita's response.

Cheers

Bobbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top