0

Hello I have convert doc file to only string text. I use this function: Reading DOC file in php:

function getRawWordText($filename) {
    if(file_exists($filename)) {
        if(($fh = fopen($filename, 'r')) !== false ) {
            $headers = fread($fh, 0xA00);
            $n1 = ( ord($headers[0x21C]) - 1 );// 1 = (ord(n)*1) ; Document has from 0 to 255 characters
            $n2 = ( ( ord($headers[0x21D]) - 8 ) * 256 );// 1 = ((ord(n)-8)*256) ; Document has from 256 to 63743 characters
            $n3 = ( ( ord($headers[0x21E]) * 256 ) * 256 );// 1 = ((ord(n)*256)*256) ; Document has from 63744 to 16775423 characters
            $n4 = ( ( ( ord($headers[0x21F]) * 256 ) * 256 ) * 256 );// 1 = (((ord(n)*256)*256)*256) ; Document has from 16775424 to 4294965504 characters
            $textLength = ($n1 + $n2 + $n3 + $n4);// Total length of text in the document
            $extracted_plaintext = fread($fh, $textLength);
            $extracted_plaintext = mb_convert_encoding($extracted_plaintext,'UTF-8');
             // if you want to see your paragraphs in a new line, do this
             // return nl2br($extracted_plaintext);
             return ($extracted_plaintext);
        } else {
            return false;
        }
    } else {
        return false;
    }  
}

This function return:

jednoznacznie implikuje poBo|enie

It should be:

jednoznacznie implikuje położenie

I try convert this string to polish letters:

return strtr ($mystring, array (
            'B' => 'ł',
            '|' => 'ż',
            ));

But I have return:

jednoznacznie implikuje po�o�enie

I add (like here: PHP output showing little black diamonds with a question mark)

header("Content-Type: text/html; charset=ISO-8859-1");

now I have this:

jednoznacznie implikuje po³o¿enie

michal
  • 1,534
  • 5
  • 28
  • 62

1 Answers1

0

DOC files are not plain text.

Try a library such as PHPWord (old CodePlex site).

nb: This answer has been updated multiple times as PHPWord has changed hosting and functionality.

Gorakh Yadav
  • 304
  • 5
  • 19