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

  • SEARCH
  • Home
  • 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 6201203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:30:36+00:00 2026-05-24T04:30:36+00:00

I have a PHP generated page containing the results of a submitted form, what

  • 0

I have a PHP generated page containing the results of a submitted form, what I would like to do is save this as a .doc file on the server.
After some googling I came across this code which I adapted:-

$myFile = "./dump/".$companyName."/testFile.doc";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);
$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData);
fclose($fh);

But the problem with this is that I would have to recreate the results in order to manually write them to the file and it doesn’t seem very efficient.

So I continued to google and found the PHP manual which left me scratching my head frankly, however I eventually found this:-

ob_start();
// code to generate page.
$out = ob_get_contents();
ob_end_clean();
// or write it to a file.
file_put_contents("./dump/".$companyName."/testFile.doc",$out);

Which will create the file, but doesn’t write anything to it. However this seems to be the way to do what (Based on the PHP manual) I want even if I can’t get it to work!

Any advice? I don’t mind googling if I can figure out a decent search term 🙂

  • 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-05-24T04:30:38+00:00Added an answer on May 24, 2026 at 4:30 am

    This sould do it for you:

    $cache = 'path/to/your/file';
    
    ob_start();
    
    // your content goes here...
    echo "hello !"; // would put hello into your file
    
    $page = ob_get_contents(); 
    
    ob_end_clean(); 
    
    $fd = fopen("$cache", "w"); 
    
        if ($fd) {
    
        fwrite($fd,$page); 
    
        fclose($fd);
    
    }
    

    It’s also a great way to cache dynamic pages. Hope it helps.

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

Sidebar

Related Questions

I'm trying to have something like the title of a page generated through PHP.
I have a two column (table based) PHP generated HTML page. I need to
I have a basic html page generated through php and it prints to a
I have many lines on my page generated from database with PHP. Each line
my page is full of php-generated content split in div's that have the same
I have an ajax generated search results page which shows all results just fine.
I have a PHP-generated page which is displaying some data about a set of
I have a PHP site where all pages include an 57K generated PHP file.
I have php code on a page which generates a series of buttons, like
I have a php generated wep page which has a lot of share buttons.

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.