Forum Moderators: coopster

Message Too Old, No Replies

What could I use to automatically edit a php file

         

kuper20

11:48 pm on Aug 6, 2008 (gmt 0)

10+ Year Member



Hi,

I have a website where I have surveys up, and whenever I need to add a new survey I need to edit my php code in my webspace. I.E. For the front end of the site, since the survey's are always a little different, I need different ways of outputting the information. There are many other small places where I need to make little changes as well.

I might be able to streamline this process a little more if I had a way of inputting on the browser the information and type for each question so it could automatically make some php code to output those survey results correctly.

Is there some way I can do this without an extra program? Could I use one php file to edit another? I don't know where the limits are.

Thanks a bunch

eelixduppy

4:51 am on Aug 7, 2008 (gmt 0)



Well, to answer your question, yes, you can write a PHP script that writes other PHP scripts, although it will get messy and hard to read pretty fast. It seems like there may be other solutions out there that you aren't seeing yet. How exactly are you making these surveys so that they aren't anywhere near the same with regards to PHP code? Do you not have some sort of content management going on here?

kuper20

12:13 am on Aug 8, 2008 (gmt 0)

10+ Year Member



actually, I don't have a content management system going on...I don't think...I guess that would really be my problem. What do you suggest?

vincevincevince

12:54 am on Aug 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think the simplest solution for you will be configuration. Write one PHP script which allows for all the variations you use, chosen by if() statements. For example, if sometimes you have no reset button, then:
if ($config['showreset']==true) $survey.="<input typ...

You can put in strings of text, or URLs to images as well.

Head up the file with a list of simple configuration statements and notes:

$config['title']="Great Survey"; // main title (Text)
$config['showreset']=false; // true/false - show the reset button?

That way you just change the configuration variable settings, and the script changes its behaviour. Do not worry about a few extra clauses which don't get run, the overhead is nothing. Unless you have one of the worlds biggest websites of course.

If you want to progress that idea further, you can make one PHP script which writes the set of configuration values in response to you filling in a form; typically they will be written to a file named config.php which is referenced by include('config.php'); in the main script.

Another option is to use a database to store the various sets of configuration; in that way you just need config to tell each survey what it's database ID is - it can do a quick SELECT and fetch the set of configuration. This has the advantage of central administration of all surveys and eliminating the need to edit PHP just to change a setting.

For design details; use CSS. Don't use inline styles, but instead control them from your external stylesheet. This is another way to avoid editing PHP.