darkfact Posted October 9, 2010 Share Posted October 9, 2010 After days of searching I found this thread http://www.phpfreaks.com/forums/index.php?topic=236954.0 that helped me do what I was trying to do. I've gotten the code to create and rename my html document but I can't figure out how to use the preg_replace part. This is my template with the 3 variables I want to replace with values from a form. <html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body><?php include_once('content.php') ?></body><SCRIPT language="JavaScript" SRC="javascript.js"></SCRIPT><script type="text/javascript"> function nametitle(){ parent.iframe1.document.getElementById("div1").innerHTML = "VARIABLE1<br>VARIABLE2";parent.iframe1.document.getElementById("quotes").innerHTML = "VARIABLE3";} </script></html> I've spent hours reading and trying to understand how to make it work but it's a little over my head. Could someone help me with this? Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/215498-preg_replace-help/ Share on other sites More sharing options...
jcbones Posted October 9, 2010 Share Posted October 9, 2010 Alright, I'll try to nail this one in one post. Your file <html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body><?php include_once('content.php') ?></body><SCRIPT language="JavaScript" SRC="javascript.js"></SCRIPT><script type="text/javascript">function nametitle(){parent.iframe1.document.getElementById("div1").innerHTML = "{{VARIABLE1}}<br>{{VARIABLE2}}";parent.iframe1.document.getElementById("quotes").innerHTML = "{{VARIABLE3}}";}</script></html> Process.php <?php//define stuff$username = $_POST['username'];$filename = "generate.html"; //replace with your filename.$destination = $username . '.html'; //this creates a file with the name of the user.//form variables:$one = $_POST['one'];$two = $_POST['two'];$three = $_POST['three'];//open the file, and read it$handle = file_get_contents($filename);//search for the variables, and replace them$search = array('{{VARIABLE1}}','{{VARIABLE2}}','{{VARIABLE3}}');$replace = array($one,$two,$three);$new = str_replace($search, $replace, $handle);file_put_contents($destination,$new);?> Quote Link to comment https://forums.phpfreaks.com/topic/215498-preg_replace-help/#findComment-1120575 Share on other sites More sharing options...
darkfact Posted October 9, 2010 Author Share Posted October 9, 2010 It works perfectly. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/215498-preg_replace-help/#findComment-1120579 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.