在php中获取docx内容的函数 [英] Function to get the content of a docx in php

查看:38
本文介绍了在php中获取docx内容的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 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;
}

我已使用上面的代码使用以下代码在我的 view 中显示 .docx 内容:

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....

请帮助我解决此问题..或建议我以任何类似的方式读取 .docx 文件的内容并将其显示在简单的 html页面视图

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

推荐答案

它现在正在工作..我正在回答我自己的问题,以便其他任何人都可以从中获取帮助...

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

问题出在这里的路径 $ path = FCPATH."uploads/document/";

已替换为 $ path ="./uploads/document/";

这篇关于在php中获取docx内容的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆