Function to get the content of a docx in php

蹲街弑〆低调 提交于 2020-01-03 05:32:05

问题


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

    $zip = zip_open($filename);

    if (!$zip || is_numeric($zip))
        return false;

    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);
    $striped_content = strip_tags($content);

    return $striped_content;
}

I have used the above code for displaying .docx content in my view using the below code:

  <div style="padding: 10px">
    <?php
    $fileName = $details->resume_name;
    $path = FCPATH . "uploads/document/";
    // i have also tried.. $path = base_url() . "uploads/document/"; and $path = FCPATH . "uploads/document/";
    $fullPath = $path . $fileName;                     
    echo $CI->docx->read_docx($fullPath);                      
    ?>
   </div>

But when I run this code it shows me nothing and the result is empty....

Please help me to solve this problem.. or suggest me any similar way to read the content of .docx file and display it in a simple html page or in a view


回答1:


its working now.. i am answering my own question so that any one else can get help from it...

the problem is with the path here $path = FCPATH . "uploads/document/";

which I have replaced with $path = "./uploads/document/";



来源:https://stackoverflow.com/questions/21362149/function-to-get-the-content-of-a-docx-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!