Have you ever faced any situation where you need to provide download option as MS-Word, Excel etc. If the situation is exactly like this (This kind of situation you might face while preparing report) then the easiest way is to prepare the html, and pass correct header to download as excel or word.
Let try an example.
<?php
$wertex = file_get_contents("http://www.wertex.org/index.php");
$len = strlen($wertex);
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/vnd.ms-excel");
header('Content-Transfer-Encoding: Binary');
//Force the download
header("Content-Length: ".$len);
header('Content-Disposition: attachment; filename="wertex.xls";');
print($wertex);
exit();?>
In the above we are simply printing the HTML and passing the header so that browser asks to download it. The rest will be handled by excel. If you don’t believe me, run the code and see the result ![]()






Whenever I need some quick information on some technical issues related to LAMP, I go through this site. Thanks to Anir and expecting lot more like this from him.