Skip to content

PHP Script to Create Microsoft Word Document Using XML and Get it as Attachment


$filename = 'my.doc';
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($filename));
header( "Content-Description: File Transfer");

$content = '<html xmlns:v="urn:schemas-microsoft-com:vml" '
        .'xmlns:o="urn:schemas-microsoft-com:office:office" '
        .'xmlns:w="urn:schemas-microsoft-com:office:word" '
        .'xmlns:m=""= '
        .'<head><meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">'
        .'<!--[if gte mso 9]>'
            font-family: Arial;
            size:215.9mm 279.4mm;  /* A4 */
            margin:14.2mm 17.5mm 14.2mm 16mm; /* Margins: 2.5 cm on each side */
        h2 { font-family: Arial; font-size: 18px; text-align:center; }
        p.para {font-family: Arial; font-size: 13.5px; text-align: justify;}
        .'<h2>Welcome To eTutorialsPoint</h2><br/>'
        .'<p class="para">'
        .'Our aim is to spread the knowledge. This website is developed for education purpose.'

        .'It contain web development tutorials, interview questions and answers and some useful development resources  ' 
        .'This website is fully responsive. We can easily study the resources on the smart phone.' 

echo $content;