【问题标题】:Convert string to polish Letters [duplicate]将字符串转换为波兰字母[重复]
【发布时间】:2018-05-31 18:21:06
【问题描述】:

您好,我已将 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

应该是:

jednoznacznie implikuje położenie

我尝试将此字符串转换为波兰字母:

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

但我有回报:

jednoznacznie implikuje po�o�enie

我添加(像这里:PHP output showing little black diamonds with a question mark

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

现在我有了这个:

jednoznacznie implikuje po³o¿enie

【问题讨论】:

  • 将读取文档的代码添加到问题中。
  • 试试header("Content-Type: text/html; charset=UTF-8");
  • 可能有用:UTF-8 all the way through
  • header("Content-Type: text/html; charset=UTF-8"); 不起作用,仍然如此。 @svgrafov 我添加链接:stackoverflow.com/a/28522157/6678345
  • @michal 您的代码应作为文本包含在问题正文中,而不是作为链接。

标签: php string converter


【解决方案1】:

DOC 文件不是纯文本。

试试PHPWord (old CodePlex site) 之类的库。

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

【讨论】:

猜你喜欢
  • 2017-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-20
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多