Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi
How to convert .doc file to plain text using PHP. I need code.
Posted
Comments
Sandeep Mewara 27-Jun-12 13:47pm    
I need code
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Sergey Alexandrovich Kryukov 27-Jun-12 13:48pm    
Why on Earth?
--SA
D.sujith kumar 27-Jun-12 14:01pm    
Hi this is my code:

$path="sa.doc";
$str = file_get_contents($path);

function count_words($string)
{
$string = htmlspecialchars_decode(strip_tags($string));
if (strlen($string)==0)
return 0;
$t = array(' '=>1, '_'=>1, "\x20"=>1, "\xA0"=>1, "\x0A"=>1, "\x0D"=>1, "\x09"=>1, "\x0B"=>1, "\x2E"=>1, "\t"=>1, '='=>1, '+'=>1, '-'=>1, '*'=>1, '/'=>1, '\\'=>1, ','=>1, '.'=>1, ';'=>1, ':'=>1, '"'=>1, '\''=>1, '['=>1, ']'=>1, '{'=>1, '}'=>1, '('=>1, ')'=>1, '<'=>1, '>'=>1, '&'=>1, '%'=>1, '$'=>1, '@'=>1, '#'=>1, '^'=>1, '!'=>1, '?'=>1); // separators
$count= isset($t[$string[0]])? 0:1;
if (strlen($string)==1)
return $count;
for ($i=1;$i

1 solution

Here is a Stack Overflow question that will get you started:

http://stackoverflow.com/questions/188452/reading-writing-a-ms-word-file-in-php[^]

Once you are able to read the Word document, you just need to then write it out to a text file.

This will not be an easy process, nor will it be a completely accurate process. You will get close but I would be shocked if you ever got a fully-working solution that was 100% accurate. Converting Word documents is not simple, and doing it in php makes it tougher.
 
Share this answer
 
Comments
D.sujith kumar 27-Jun-12 13:45pm    
i need step by step process.
Tim Corey 27-Jun-12 13:47pm    
Sorry, I don't have one for you. You are going to need to do your own legwork on this one. The link above gives you full code snippets. Start there and see how far you get.
Sergey Alexandrovich Kryukov 27-Jun-12 13:47pm    
The problem is not 100% accuracy, the problem is that the term "convert" is not strictly defined here, that's it.
Other than that, this is a pretty accurate answer, I don't know know how many per cent; my 5 :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900