2016-07-11 3 views
0

단락 (PREG_SPLIT, "/\.\n/u")로 .DOCX 분할 먼저 docxConversion 클래스 ** 첫 번째 함수를 사용하여 부분으로 분할 ** read_docxPHP는 <strong>은 DOCX</strong> 읽기에 내가 시도하고

private function read_docx(){ 
    $striped_content = ''; 
    $content = ''; 

    $zip = zip_open($this->filename); 

    if (!$zip || is_numeric($zip)) return false; 
    $zip_entry = zip_read($zip); 
    while ($zip_entry = zip_read($zip)) { 
     if (zip_entry_open($zip, $zip_entry) == FALSE) continue; 
     if (zip_entry_name($zip_entry) != "word/document.xml") continue; 
     $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));    
     zip_entry_close($zip_entry); 
    }// end while 

    zip_close($zip);   
    $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content); 
    $content = str_replace('</w:r></w:p>', "\r\n", $content); 
    $content = str_replace("</w:p>", "\r\n", $content); 

    $pattern = "/(الفقرة\s[0-9]+\s)|(الأولى الفقرة)./u";//المادة\s*\d: 

    $striped_content = strip_tags($content);    
    $splitted_para_arr = preg_split($pattern,$striped_content,null,PREG_SPLIT_NO_EMPTY); 

    return $splitted_para_arr;//striped_content; 
} 

번째 함수는 그 후 후속하여 문단으로 각 부분을 분할

public function convertToText() { 
     if(isset($this->filename) && !file_exists($this->filename)) { 
     return "File Not exists"; 
    } 
    $fileArray = pathinfo($this->filename); 
    $file_ext = $fileArray['extension'];   
     if($file_ext == "docx") { 
      return $this->read_docx();    
     } else { 
      return "Invalid File Type"; 
     } 
    } 

텍스트로 변환된다 기능

public function getParag($article){ 
    $splitted_para_arr = preg_split("/\.\n/u",$article,null,PREG_SPLIT_NO_EMPTY);   
    return $splitted_para_arr;//striped_content; 
} 

보내고 그러나 여기에서 문제는 당신이 어떤 종류의 처리하려면 나는 다음과 같은 패턴 "/.\n/u"

+1

'. \ n'은 윈도우 스타일의'\ r \ n' 개행을 사용하기 때문에 유효한 순서가 아닌 것 같습니다. 어쩌면'. \ r \ n '과 같은 정규 표현식이 효과적 일지 모르지만'. \ r \ n'이 작동 할 수도 있습니다. – apokryfos

+0

@apokryfos 고맙습니다. 저의 의견이 맞습니다. –

답변

1

으로 단락을 얻을 수있다 LINEBREAK, \R 사용

$splitted_para_arr = preg_split("/\.\R/", $article, null, PREG_SPLIT_NO_EMPTY); 

\R 경기 \n, \r 또는 \r\n

+0

'\ v'보다는'\ R' 인 이유가 뭔가요? – CD001

+0

@ CD001 :'\ v'는'\ R'보다 더 일치합니다, 예를 들어'FF' (form feed) – Toto