1

i need to save contents of webpage on word. i need to keep the links and formating too. if i send

$ter=$ter. "<a href='$url'>".$chunk."</a> ";
 $fp  =  fopen("test.doc",  'w+'); 
        $str  =  $ter;

        fwrite($fp,  $str); 

        fclose($fp);

i get a word document but i loose the links ..it comes out as

a href='http://www.google.com/search?q=sells+sea+shells%0D%0A'>sells sea shells

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
shazia
  • 179
  • 1
  • 2
  • 22

1 Answers1

1

Going along with this weird pretend ".doc" file which Word (2007) does seem to display as a document; if I change your fwrite line:

fwrite($fp,  '<html><body>' . $str . '</body></html>');

It works.

thirtydot
  • 224,678
  • 48
  • 389
  • 349
  • I think it works because Word reads the file, and notices that it isn't actually in the .doc file format. So, it then tries to guess what kind of file it is and realizes it's HTML, so it handles it as such. If you open your generated file in Word, save it again, and then open the saved file in Notepad, you will see that Word has saved it as (it's own brand of extremely convoluted) HTML. Despite the .doc extension. – thirtydot Dec 11 '10 at 14:56
  • Alternatively, you might want to take a look at this: http://phpword.codeplex.com/ – thirtydot Dec 12 '10 at 21:03
  • For a more elaborate explanation of the technique mentioned above, check this article - codeproject.com/kb/office/Wordyna.aspx – mvark Feb 01 '11 at 02:41