Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTF increases support for Chinese reading #2590

Open
lrjxgl opened this issue Mar 22, 2024 · 0 comments
Open

RTF increases support for Chinese reading #2590

lrjxgl opened this issue Mar 22, 2024 · 0 comments

Comments

@lrjxgl
Copy link

lrjxgl commented Mar 22, 2024

I have updated the code about reader/rtf.php
`<?php
/**

namespace PhpOffice\PhpWord\Reader;

use Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Reader\RTF\Document;

/**

  • RTF Reader class.
  • @SInCE 0.11.0
    /
    class RTF extends AbstractReader implements ReaderInterface
    {
    /
    *
    • Loads PhpWord from file.

    • @param string $docFile

    • @return \PhpOffice\PhpWord\PhpWord
      */
      public function load($docFile)
      {
      $phpWord = new PhpWord();

      if ($this->canRead($docFile)) {

       $doc = new Document();
      
       $b1= file_get_contents($docFile);
        
       $b1=preg_replace_callback("/(\\\\'[\w]{2}\\\\'[\w]{2})/iUs",function($e){
       	 
       	$t=str_replace("\'","",$e[1]);
       	return iconv("gb2312","utf-8", pack('H*', strtoupper($t)));
       },$b1);
       $doc->rtf=$b1;
       $doc->read($phpWord);
      

      } else {
      throw new Exception("Cannot read {$docFile}.");
      }

      return $phpWord;
      }
      }
      `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant