1

I want to display a word file and then extract the content and display it in a separate textarea. i want to do away with the formatting as well.

this is what i get when i get the read the text file using php

������ÿÿÿÿ�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Running Head: INTERNATIONAL BUSINESS International Business [Name of the writer] [Name of the institution] International Business Question 1 Increasing returns to scale (or economies of scale) in production is an indisputable phenomenon characterizing real world production, and, as such, they have long been recognized as a principal source of economic prosperity. Nonetheless, they have never played a major role in

this is the code

$fh = fopen($newname, 'r'); 
$contents => fread($fh, filesize($newname));
fclose($fh); unlink($newname); echo
"<br/>"; echo $contents;

how can i get rid of all these charecters.

Thanks

deceze
  • 510,633
  • 85
  • 743
  • 889
shazia
  • 179
  • 1
  • 2
  • 22
  • Word documents do not simply contain plain text, they need to be parsed by something that can parse the proprietary .doc format. See [Reading/Writing a MS Word file in PHP](http://stackoverflow.com/questions/188452/reading-writing-a-ms-word-file-in-php) – deceze Dec 24 '10 at 05:53
  • 1
    The .doc format is incredibly complicated (in fact, it's basically a file system in itself). Joel Spolsky (who also co-founded this site) wrote an article on the matter a few years back at http://www.joelonsoftware.com/items/2008/02/19.html – Rafe Kettler Dec 24 '10 at 05:56

2 Answers2

1

This will help you to send the file to client system and they will be able to download it.

<?php
$filename = "test.doc";


if(!file_exists($filename) ) {
    die("The file '{$filename}' does not exist.");
}

header("Content-Type; application/msword");
header("Content-Disposition: attachment; filename=". basename($filename));
header("Content-Length: ". filesize($filename));
header("Content-Transfer-Encoding: binary");


readfile($filename);
?>
rajmohan
  • 1,618
  • 1
  • 15
  • 36
-1

See this question: Reading/Writing a MS Word file in PHP.

Community
  • 1
  • 1
ariefbayu
  • 21,849
  • 12
  • 71
  • 92