2014-03-05 5 views
0

MS 워드 파일을 먼저 zip으로 변환 한 다음 XML을 가져 와서 읽습니다.PHP에서 MS 워드 파일 읽기

하지만 줄 바꿈 문자가 제거되어 나를 괴롭 히고 있습니다. 나는 어떻게해야합니까? 당신을 도움이된다면

function get_docx_content($filename) { 
    //Check for extension 
    $ext = end(explode('.', $filename)); 

    //if its docx file 
    if($ext == 'docx') 
    $dataFile = "word/document.xml"; 
    //else it must be odt file 
    else 
    $dataFile = "content.xml"; 

    //Create a new ZIP archive object 
    $zip = new ZipArchive; 

    // Open the archive file 
    if (true === $zip->open($filename)) { 
     // If successful, search for the data file in the archive 
     if (($index = $zip->locateName($dataFile)) !== false) { 
      // Index found! Now read it to a string 
      $text = $zip->getFromIndex($index); 
      // Load XML from a string 
      // Ignore errors and warnings 
      $xml = DOMDocument::loadXML($text, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING); 
      // Remove XML formatting tags and return the text 
      return strip_tags($xml->saveXML()); 
     } 
     //Close the archive file 
     $zip->close(); 
    } 
} 

답변

0

이 시도 :

은이 코드를 사용합니다. 난 단지 12 의미 단어가 있었을 때

<?php 



/***************************************************************** 
This approach uses detection of NUL (chr(00)) and end line (chr(13)) 
to decide where the text is: 
- divide the file contents up by chr(13) 
- reject any slices containing a NUL 
- stitch the rest together again 
- clean up with a regular expression 
*****************************************************************/ 

function parseWord($userDoc) 
{ 
    $fileHandle = fopen($userDoc, "r"); 
    $line = @fread($fileHandle, filesize($userDoc)); 
    $lines = explode(chr(0x0D),$line); 
    $outtext = ""; 
    foreach($lines as $thisline) 
     { 
     $pos = strpos($thisline, chr(0x00)); 
     if (($pos !== FALSE)||(strlen($thisline)==0)) 
      { 
      } else { 
      $outtext .= $thisline." "; 
      } 
     } 
    $outtext = preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\[email protected]\/\_\(\)]/","",$outtext); 
    return $outtext; 
} 

$userDoc = "cv.doc"; 

$text = parseWord($userDoc); 
echo $text; 


?> 

그 다음

http://www.blogs.zeenor.com/it/read-ms-word-docx-ms-word-2007-file-document-using-php.html

+0

들여다 당신이 연구에 대한 자세한 내용을 원하는 경우에는 불행하게도 그것은 수백보다 알 수없는 문자의 혼란 더 초래하지 않습니다. –