<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CoryMathews.com &#187; PHP</title>
	<atom:link href="http://corymathews.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://corymathews.com</link>
	<description>Things I should remember and then some...</description>
	<lastBuildDate>Wed, 04 Aug 2010 18:32:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Saving a PHP File as a Word Document</title>
		<link>http://corymathews.com/287/saving-a-php-file-as-a-word-document/</link>
		<comments>http://corymathews.com/287/saving-a-php-file-as-a-word-document/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 12:43:27 +0000</pubDate>
		<dc:creator>CoryMathews</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[word]]></category>

		<guid isPermaLink="false">http://corymathews.com/?p=287</guid>
		<description><![CDATA[So you are looking for a way to save a PHP page as a word doc programatically? Then you have come to the right place. When I had to overcome this problem my main requirement was that I could not open word on the server. Searching around the net produced countless pages with the same [...]]]></description>
			<content:encoded><![CDATA[<p>So you are looking for a way to save a PHP page as a word doc programatically? Then you have come to the right place.</p>
<p>When I had to overcome this problem my main requirement was that I could <strong>not open word on the server</strong>.</p>
<p>Searching around the net produced countless pages with the same responses of using <a href="http://www.php.net/manual/en/class.com.php">COM</a> or using some third party library&#8217;s and software. However as with any project if it is possible I, as well as many other developers, try to avoid third party <a href="http://www.codinghorror.com/blog/archives/000497.html">products</a>.</p>
<p>I eventually came up with this solution:</p>
<pre name="code" class="html">&lt;?php
	header("Content-type: application/vnd.ms-word");
	header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?&gt;</pre>
<p>Then along with your meta tags add the following</p>
<pre name="code" class="html">&lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\"&gt;</pre>
<p>Placing this meta tag on a page will cause the browser to think it is a html word document. Thus prompting you to open/save the document instead of rendering it like a normal webpage.</p>
<p>The only downside to this is that when you open the file in word it will open in the web layout mode of word instead of print layout.</p>
<h3>Example Usage:</h3>
<p><a href="http://www.isearchnotes.com/single.php?id=136">You can view a demo of this in use over at iSearchNotes.com</a></p>
<p><strong>Word Page</strong>: (<a href="http://corymathews.com/src/SaveAsWordDoc.php">SaveAsWordDoc.php</a>)</p>
<pre name="code" class="html">&lt;?php
	header("Content-type: application/vnd.ms-word");
	header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\"&gt;
&lt;title&gt;Saves as a Word Doc&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Header&lt;/h1&gt;
  This text can be seen in word
&lt;ul&gt;
&lt;li&gt;List 1&lt;/li&gt;
&lt;li&gt;List 2&lt;/li&gt;
&lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>Calling Page:</strong><br />
Just your normal html <a> link.</p>
<pre name="code" class="html"><a href="SaveAsWordDoc.php">link</a></pre>
<p></a></p>
]]></content:encoded>
			<wfw:commentRss>http://corymathews.com/287/saving-a-php-file-as-a-word-document/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
