Jump to content

php function, or smart php?


fullyscintilla

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.