How to count words in doc,xls,pdf and txt file

xiaoan

New Member
I have a scenario in which I need to count the number of words in file.I have different file formats such as \[code\].doc\[/code\], \[code\].xls\[/code\], \[code\].pdf\[/code\] and \[code\].txt\[/code\]. I am using this method for counting:\[code\]<form method="post" action="" enctype="multipart/form-data"> <input type="file" name="docfile" /> <input type="submit" name="submit" /></form><?php if(isset($_POST['submit'])){ $file = $_FILES['docfile']['name']; $file = str_replace(" ","_",$file); //$file = file_get_contents($file); $ext = pathinfo($file, PATHINFO_EXTENSION); move_uploaded_file($_FILES['docfile']['tmp_name'],"uploads/".$file); if($ext == "txt" || $ext == "pdf" || $ext == "doc" || $ext == "docx"){ $file = file_get_contents("uploads/".$file); echo str_word_count($file); } }?>\[/code\]But it is not returning the correct word count for the file.
 
Back
Top