I wrote a piece of code by piecing together bits from tutorials on fopen and outputting it in word doc.
But looking back I don't get how it works. Here is the code:
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <title>Some title</title>
- </head>
- <body>
- <h1>A title </h1>
- <?php
- $content="<html><p><h2>some text</h2></p></html>";
- print $content;
- $myFile = "my_report.doc";
- $fh=fopen($myFile, 'w') or die("cant write file");
- fwrite($fh, $content);
- fclose($fh);
- // Set up the file name
- $fileName = "my_file";
- header("Content-type: application/vnd.ms-word");
- header('Content-Disposition: attachment; filename="'.$fileName.'.doc"');
- ?>
- </body>
- </html>
1) The $fileName onwards has no link to the code involving fopen to fclose, so not sure how it reads the file I have written to.
2) I want it to only write whatever is written in $content. However this piece of code writes both:
A Title
Some text
Would be great if someone could show me how this works. Many thanks.