PHP
  Home arrow PHP arrow Page 4 - PHP and COM
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP and COM
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 13
    2002-04-23


    Table of Contents:
  • PHP and COM
  • Striving To Excel
  • The Number Game
  • Export Potential
  • Keeping It Simple
  • Access-ing The Web
  • All For One, And One For All
  • New Coins For Old
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    PHP and COM - Export Potential
    ( Page 4 of 9 )

    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.



    <?php // where are the files stored? $PathToDocumentFolder = "C:\\My Stuff\\Documents"; ?> <html> <head> <basefont face="Arial"> <title>My Documents</title> </head> <body> <h2>My Documents</h2> <table border="2" cellpadding="5" cellspacing="1" width="90%"> <tr> <th width="55%" align="left">Name</th> <th width="20%" align="center">&nbsp;</th> <th width="20%" align="center">&nbsp;</th> </tr> <?php // get a handle to the document folder $dHandle = dir($PathToDocumentFolder); // iterate through the file list while($dContent=$dHandle->read()) { // only list the .doc files if(substr($dContent,-4)== ".doc") { ?> <tr> <td width="55%" align="left"><?php echo $dContent; ?></td> <td width="20%" align="center"><a href="<?php echo $PathToDocumentFolder."\\".$dContent; ?>">View as Word</a></td> <td width="20%" align="center"><a href="<?php echo "htmlviewer.php?DocumentPath=".$PathToDocumentFolder."\\".$dContent; ?>">View as HTML</a></td> </tr> <?php } } // close the handle to the directory $dHandle->close(); ?> </table> </body> </html>
    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.

    <?php // where are the files stored? $PathToDocumentFolder = "C:\\My Stuff\\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.

    <?php // get a handler to the document folder $dHandle = dir($PathToDocumentFolder); // iterate through the file list while($dContent=$dHandle->read()) { // only list the .doc files if(substr($dContent,-4)== ".doc") { ?> <tr> <td width="55%" align="left"><?php echo $dContent; ?></td> <td width="20%" align="center"><a href="<?php echo $PathToDocumentFolder."\\".$dContent; ?>">View as Word</a></td> <td width="20%" align="center"><a href="<?php echo "htmlviewer.php?DocumentPath=".$PathToDocumentFolder."\\".$dContent; ?>">View as HTML</a></td> </tr> <?php } } ?>
    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.

     
     
    >>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT