Jump to content

Doing Wordcount in PHP of files like DOC, RTF, TXT


tvks

Recommended Posts

Hi all,

 

I am right now stuck with a project of selecting multiple files (File

format: only doc, txt and rtf) and onclick of the submit, I must

generate a report on how many characters, words, line breaks,

sentences are there in each of the selected files.

 

Thanx for any help,

 

Regards

 

tvks

The text file bit is easy

<?php
    $txt = file_get_contents('myfile.txt');
    
    $chars = count_chars($txt);
    $w = str_word_count($txt);
    $c = strlen($txt) ;
    
    echo "Characters : $c <br>";
    echo "Words    : $w <br>" ;
    echo "Sentences : $chars[46] <br>";
    echo "Newlines : $chars[13] <br>";
    
?>

 

For the Word and rtf files you will need COM objects. The properties and methods available for word documents can be at the MSDN site.

 

Try Googling "PHP COM WORD"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.