Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:58:35+00:00 2026-06-12T23:58:35+00:00

I have a lot of .doc files with entry specifications for a database. I

  • 0

I have a lot of .doc files with entry specifications for a database. I need to parse through all of these documents and create entries with the information within the documents. I have been trying to use the COM approach. The file has plain text on the top and at the bottom of the page… however, the specifications are in a table at the center of the page. If I don’t unlink the new .txt file I can see that the content is transfered to the new document, but it has a bunch of invalid characters in the form of [] running throughout it. When I use file_get_contents() it completely ignores all of the text from the table.

Is there someway to programmatically take care of this? I can’t really find any information on the API of the word.application COM object. Ideally I’m thinking I should strip the formatting then save the file as a .txt file or something to that effect.

Any help would be greatly appreciated.

Here is my code:

    $dir   = $PATH."/scripts/specsheets/doc";
    $files = scandir($dir);
    foreach( $files as $file ) {
        if( strtolower(substr($file, -3)) == "doc" ) {

            $word = new COM("word.application") or die("Unable to instantiate Word");
            $word->Documents->Open($dir."/".$file);
            $new_file = substr($dir."/txt/".$file, 0, -4).".txt";

            $word->Documents[1]->SaveAs($new_file, 2);
            $word->Documents[1]->Close(false);
            $word->Quit();
            $word = NULL;
            unset($word);

            $output = file_get_contents($new_file);
            rename($dir."/".$file, $dir."/archive/".$file);

            echo utf8_encode($output);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:58:36+00:00Added an answer on June 12, 2026 at 11:58 pm

    Can’t find a solution using the COM approach… but you can use the antiword program for Windows to get the output if you use this command in php

    $content = shell_exec("C:/antiword/antiword.exe ".$filename);
    

    the link for the windows version is:

    http://www-stud.rbi.informatik.uni-frankfurt.de/~markus/antiword/

    It works very well, it even extracts the data in the tables. Definitely solved my issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have hundreds of .doc files with text that I need put on web
I have a folder with lot of files like doc, excel, ppt etc. Once
I have been reading a lot of django articles, including the official doc. Occasionally,
At the moment, I have lot's of Java which does all kind of nifty
I need to post several (read: a lot) PDF files to the web but
I have a lot of callable objects and they all have the __doc__ string
I have to analyze a lot of XML files in my current project. I
I have a option to attach files within a application. I this I need
I have a requirement to store user uploaded files to the database (filesystem is
I have found a lot of answer on this question, but they are all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.