fullyscintilla Posted August 11, 2009 Share Posted August 11, 2009 Hello everyone, Sorry about my elusive title. I was unsure exactly what the subject would be called. I've been trying to overhaul some of my processing code from an app that I have been working on and while I've already come up with a solution I'm not sure if there is a better one. Basically I am taking user input through a form and sending it to a processing page. The processing page runs checks on the submitted data for error or proper entry. Then Stores the the data in a session and sends the user to a final display page. The data is then ran through some basic math calculations and displayed to the user. On the processing page I have a main Switch method that Changes what needs to be done based on which method is being used. Heres where the coding got cumbersome. For each case I was writing alot of repitive tasks but tasked that utlized alot of different variables. I thought about creating a main function to handle those tasked but quickly found that My function would of had to have an outrageous number of arguments. So I instead told php to create a new processing page to handle the data like a function but without having to pass all the variables into it. So if your still following me.. sorry if i'm hard to understand.. i stink at explaining this. Basically what I've got now.. is PHP pulls in a "template" file that has all the code needed to process the data, but saved as a string to be output into a new file. As an example of what the template php file looks like \/: <?php $endTag ="?>"; //Template variable to be put into fwrite() function $template = '<?php if($'.$Variable.' != \\'null\') { $'.$Variable.'_Query = "'.$SarrayQuery.' AND time=\'04:00\'"; } '; echo($endTag); ?> then after this file gets written.. I turn around and pull it into php to parse the code. But it makes we wonder if theres not an easier/more effcient way to do this. thanks, fully (Some of the code was stripped out by the board's posting functions) Link to comment https://forums.phpfreaks.com/topic/169702-php-function-or-smart-php/ Share on other sites More sharing options...
fullyscintilla Posted August 11, 2009 Author Share Posted August 11, 2009 i guess a better way of saying all this is i've told php to write the code for me. Then use it. I was just wondering if anyone knew a better way to do it. Because for one, this way requires the directory to not be write protected. As its actually writting its own code to parse and creating a new file in the process. Link to comment https://forums.phpfreaks.com/topic/169702-php-function-or-smart-php/#findComment-895293 Share on other sites More sharing options...
oni-kun Posted August 11, 2009 Share Posted August 11, 2009 i guess a better way of saying all this is i've told php to write the code for me. Then use it. I was just wondering if anyone knew a better way to do it. Because for one, this way requires the directory to not be write protected. As its actually writting its own code to parse and creating a new file in the process. Well, that seems a bit excessive. Note you can use 'eval()' to parse PHP from a string or text or file. $message = 'Hey!'; //Dynamic element $template = 'require("header.php"); echo '.$message.'; require("footer.php");'; eval($template); $template = '<?php'.$template.'?>'; //write new template.. $fp = fopen('newtemplate.php', 'w'); fwrite($fp, $template); fclose($fp); Link to comment https://forums.phpfreaks.com/topic/169702-php-function-or-smart-php/#findComment-895299 Share on other sites More sharing options...
fullyscintilla Posted August 11, 2009 Author Share Posted August 11, 2009 Thanks oni-kun, I believe that is exactly what I was looking for. I just needed a way to change variable names dynamically. This should do her. fully (Also does anyone else have a problem with advertisements blocking the submit button during quick-edit?) Link to comment https://forums.phpfreaks.com/topic/169702-php-function-or-smart-php/#findComment-895825 Share on other sites More sharing options...
Maq Posted August 11, 2009 Share Posted August 11, 2009 (Also does anyone else have a problem with advertisements blocking the submit button during quick-edit?) No. But if it's an ongoing issue then you can create a thread here: PHPFreaks.com Questions, Comments, & Suggestions. Note: If your thread is solved please mark as so, thanks. Link to comment https://forums.phpfreaks.com/topic/169702-php-function-or-smart-php/#findComment-895839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.