将字符串转换为波兰字母

时间:2017-12-18 11:52:37

标签: php string converter

您好我已将doc文件转换为仅字符串文本。我使用这个函数: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;
    }  
}

此函数返回:

  

jednoznacznie implikuje poBo | enie

应该是:

  

jednoznacznieimplikujepołożenie

我尝试将此字符串转换为抛光字母:

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

但我已经回来了:

  

jednoznacznieimplikujepo o enie

我添加(例如:PHP output showing little black diamonds with a question mark

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

现在我有了这个:

  

jednoznacznieimplikujepo³o¿enie

1 个答案:

答案 0 :(得分:0)

DOC文件不是纯文本。

尝试使用PHPWordold CodePlex site)等库。

nb:由于PHPWord已更改托管和功能,此答案已多次更新。