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
https://forums.phpfreaks.com/topic/215498-preg_replace-help/
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
https://forums.phpfreaks.com/topic/215498-preg_replace-help/#findComment-1120575
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.