muuucho Posted November 2, 2016 Share Posted November 2, 2016 I am trying to create a dynamic script generator. My idea is to have the following scripts: input.php $colour="brown"; $animal ="cat"; template.php echo "<p>This is a $colour \$animal</p>"; magic.php (This script is what I need help to write) takes input.php and template.php and creates and saves a file output.php like this: output.php echo "<p>This is a brown $animal.</p>; So, when I run... index.php $animal = "cow"; require ('output.php'); ...I get this in my browser: This is a brown cow Quote Link to comment https://forums.phpfreaks.com/topic/302454-create-a-script-generator/ Share on other sites More sharing options...
requinix Posted November 2, 2016 Share Posted November 2, 2016 This is really just templating. Just about any templating solution will work. Do you really want the input and template files to be valid PHP code? Doesn't seem like a good idea to me. I mean, it's not like you can execute them as they are now. How about simpler stuff like (input.ini) colour = "brown" animal = "cat" (template.php.tpl) <?php echo "<p>This is a {{colour}} $animal.</p>"; <?php $variables = parse_ini_file("input.ini"); $template = file_get_contents("template.php.tpl"); $pairs = array(); foreach ($variables as $name => $value) { $pairs["{{" . $name . "}}"] = $value; } echo strtr($template, $pairs); Quote Link to comment https://forums.phpfreaks.com/topic/302454-create-a-script-generator/#findComment-1538891 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.