Word Documents with PHP
I’ve just had the need to automatically generate word documents for the [FAS website] and I have to say I was surprised quite how simple that was with PHP. Well its kinda a fudge in that all I do is write HTML that openoffice understands and set the doctype to msword… does the trick nicely and here is a quick example ([inspiration for this]:
$fp = fopen($filename, “w”);
$test = “here is something really important that must be in a word document – argh”;
header(‘Content-disposition: attachment; filename=$filename);
Of course I was extracting the data from a mysql database and parsing that into the document – quite please with that really.
Oh and page breaks when making .doc files in php are useful:
<p style=”page-break-before: always” >