Let's look at something a little more interesting. I've always considered Microsoft Word to be one of the best editing tools to ever come out of Redmond - and one of its nicest features, especially for Web newbies, is the ability to quickly convert a formatted Word document into an HTML file suitable for use on a Web site. That's where my next example comes in. It uses Word's built-in export-to-HTML feature in combination with a PHP script to give new meaning to the term "tighter Web integration". Watch, and be awed! The first step here is to write a script that displays a list of all the Word documents available on the system. There's nothing fancy here - this is just very basic usage of PHP's file and directory functions. Here's what it looks like: ![]() The first step here is to initialize a variable containing the location of the directory containing the Word documents. Next, a table is generated and a PHP "while" loop is used to populate it with a file list of Word documents in that directory. Within this code block, the first step is to create a directory handle for the named location. This "pseudo-object" gives me access to several methods that will allows us to read the contents of the directory, move back to the root folder, close this handle and so on. Once I have the object created, I've used a "while" loop to read the contents of the directory, and an "if" test to filter out all the non-Word files, on the basis of the ".doc" file extension. Each of the files in the final list is then displayed as a separate row in the table, complete with links to view it, either as a Word document within the browser itself, or as an HTML document via the "htmlviewer.php" script. This "htmlviewer.php" script is where all the meat really is. Let's take a look at that next.
blog comments powered by Disqus |