php - 如何将Word文档中的问题和答案批量上传到MYSQL数据库?

标签 php mysql codeigniter math

我正在尝试从 Word 文档批量上传问题和答案。其中包含带有答案的问题,例如

**I have attached the screenshot of model question paper**

我正在使用以下 PHP 类

class Doc2Txt {
private $filename;

public function __construct($filePath) {
    $this->filename = $filePath;
}

private function read_doc() {
    $fileHandle = fopen($this->filename, "r");
    $line = @fread($fileHandle, filesize($this->filename));   
    $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\t@\/\_\(\)]/","",$outtext);
    return $outtext;
}

private function read_docx(){

    $striped_content = '';
    $content = '';

    $zip = zip_open($this->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;
}

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 == "doc" || $file_ext == "docx")
    {
        if($file_ext == "doc") {
            return $this->read_doc();
        } else {
            return $this->read_docx();
        }
    } else {
        return "Invalid File Type";
    }
}
}

将这些类型的数学数据保存在数据库中的过程是什么?或者请让我知道,我怎样才能实现这一目标。

最佳答案

当我们将数学公式粘贴到excel中时,它可以正确显示,但是当我们尝试将其粘贴到word或其他编辑器中时,公式将更改为E= A/(H_2位移的wt.)×E_H

因此,如果我们发现 Excel 中发生数据转换,我们也可以轻松地在 MYSQL 数据库中执行此操作

关于php - 如何将Word文档中的问题和答案批量上传到MYSQL数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28274255/

相关文章:

mysql - 将 Ruby API 请求信息记录到数据库

codeigniter - 设置 CodeIgniter 4.2 时如何解决错误 "unexpected ' _592_00 0'"?

javascript - 如何在 codeigniter 中制作星级评分系统?

mysql - 如何在codeigniter中从两个不同的表中选择具有相同列名的数据

php - 使 JSON 数组 Flot 兼容

用于发送数据的 PHP Ratchet 套接字客户端

php - 从 PHP(使用 mysqli)为 MySQL 准备语句

php - 将数组内容存入数据库

php - 图像高度不适用于 php 循环

php - 我们如何在php中获取当前登录用户的用户名?