Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9115291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:23:46+00:00 2026-06-17T04:23:46+00:00

I’d like to write a few lines to a template file on my server

  • 0

I’d like to write a few lines to a template file on my server from my php webpage and then download a copy of it.

I’ll use main.php that contains the form to be filled. It has input fields for changeme1 and changeme2.

I’ll use create.php that will read in the POSTed details from main.php and write them out to template.php which is structured as below (but much larger and complex):

<html>
<head>
<title>Test1</title>
</head>

<body>
<p>{changeme1}</p>
<p>{changeme2}</p>

</body>
</html>

Is there a way I can read this template.php in, make the mods to {changeme1} and {changeme2} and write back out to a downloadable file? I’m thinking search and replace perhaps?

I have already managed to get the download of a file via headers working using other info found on SO here:
PHP create file for download without saving on server

but this method echoes the html stuff where I need to simply write where the curly brackets are. Because of the final size of template.php echoing would not be suitable as it would mean a lot of work after every template change, modifying the template suitable for php echoing (hope you understand me here).

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:23:47+00:00Added an answer on June 17, 2026 at 4:23 am

    You can load the file contents into a variable by using file_get_contents() and then use str_replace() to replace the strings in questions.

    <?php
    $search  = array('{changeme1}', '{changeme2}');   // what will be searched for
    $replace = array('foo', 'bar');                   // replace it with this
    
    $file = file_get_contents ('filename.tpl');
    $new  = str_replace ($search, $replace, $file);
    
    // $new now contains the template file contents with the values replaced, 
    // do what you want with it
    echo $new;
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I would like to count the length of a string with PHP. The string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.