Jump to content

preg_replace help


darkfact

Recommended Posts

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,

Link to comment
Share on other sites

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);?>

 

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.