下面小编就为大家带来一篇php解析mht文件转换成html的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

php解析mht文件,使用编辑器打开可以看到base64编码所以,mht是可以转换成html的。

/**

* 针对Mht格式的文件进行解析

* 使用例子:

*

* function mhtmlParseBody($filename) {

if (file_exists ( $filename )) {

if (is_dir ( $filename )) return false;

$filename = strtolower ( $filename );

if (strpos ( $filename, '.mht', 1 ) == FALSE) return false;

$o_mhtml = new mhtml ();

$o_mhtml->set_file ( $filename );

$o_mhtml->extract ();

return $o_mhtml->get_part_to_file(0);

}

return null;

}

function mhtmlParseAll($filename) {

if (file_exists ( $filename )) {

if (is_dir ( $filename )) return false;

$filename = strtolower ( $filename );

if (strpos ( $filename, '.mht', 1 ) == FALSE) return false;

$o_mhtml = new mhtml ();

$o_mhtml->set_file ( $filename );

$o_mhtml->extract ();

return $o_mhtml->get_all_part_file();

}

return null;

}

*/

class mhtparse {

var $file = '';

var $boundary = '';

var $filedata = '';

var $countparts = 1;

var $log = '';

function extract() {

$this->read_filedata ();

$this->file_parts ();

return 1;

}

function set_file($p) {

$this->file = $p;

}

function get_log() {

return $this->log;

}

function file_parts() {

$lines = explode ( "\n", substr ( $this->filedata, 0, 8192 ) );

foreach ( $lines as $line ) {

$line = trim ( $line );

if (strpos ( $line, '=' ) !== FALSE) {

if (strpos ( $line, 'boundary', 0 ) !== FALSE) {

$range = $this->getrange ( $line, '"', '"', 0 );

$this->boundary = "--" . $range ['range'];

$this->filedata = str_replace ( $line, '', $this->filedata );

break;

}

}

}

if ($this->boundary != '') {

$this->filedata = explode ( $this->boundary, $this->filedata );

unset ( $this->filedata [0] );

$this->filedata = array_values ( $this->filedata );

$this->countparts = count ( $this->filedata );

} else {

$tmp = $this->filedata;

$this->filedata = array (

$tmp

);

}

}

function get_all_part_file() {

return $this->filedata;

}

function get_part_to_file($i) {

$line_data_start = 0;

$encoding = '';

$part_lines = explode ( "\n", ltrim ( $this->filedata [$i] ) );

foreach ( $part_lines as $line_id => $line ) {

$line = trim ( $line );

if ($line == '') {

if (trim ( $part_lines [0] ) == '--')

return 1;

$line_data_start = $line_id;

break;

}

if (strpos ( $line, ':' ) !== FALSE) {

$pos = strpos ( $line, ':' );

$k = strtolower ( trim ( substr ( $line, 0, $pos ) ) );

$v = trim ( substr ( $line, $pos + 1, strlen ( $line ) ) );

if ($k == 'content-transfer-encoding') {

$encoding = $v;

}

if ($k == 'content-location') {

$location = $v;

}

if ($k == 'content-type') {

$contenttype = $v;

}

}

}

foreach ( $part_lines as $line_id => $line ) {

if ($line_id <= $line_data_start)

$part_lines [$line_id] = '';

}

$part_lines = implode ( '', $part_lines );

if ($encoding == 'base64')

$part_lines = base64_decode ( $part_lines );

elseif ($encoding == 'quoted-printable')

$part_lines = imap_qprint ( $part_lines );

return $part_lines;

}

function read_filedata() {

$handle = fopen ( $this->file, 'r' );

$this->filedata = fread ( $handle, filesize ( $this->file ) );

fclose ( $handle );

}

function getrange(&$subject, $Beginmark_str = '{', $Endmark_str = '}', $Start_pos = 0) {

/*

* $str="sssss { x { xx } {xx{xx } x} x} sssss"; $range=string::getRange($str,'{','}',0); echo $range['range'];

//tulem: " x { xx } {xx{xx } x} x" echo $range['behin'];

//tulem: 6 echo $range['end'];

//tulem: 30 (' ') -- l5pumärgist järgnev out: array('range'=>$Range,'begin'=>$Begin_firstOccurence_pos,'end'=>$End_sequel_pos) |

false v1.1 2004-2006,Uku-Kaarel J5esaar,ukjoesaar@hot.ee,http://www.php.cn/,+3725110693

*/

if (empty ( $Beginmark_str ))

$Beginmark_str = '{';

$Beginmark_str_len = strlen ( $Beginmark_str );

if (empty ( $Endmark_str ))

$Endmark_str = '}';

$Endmark_str_len = strlen ( $Endmark_str );

/* $Start_pos_cache = 0; */

do {

/* !algus */

if (! is_int ( $Begin_firstOccurence_pos ))

$Start_pos_cache = $Start_pos;

/* ?algus-test */

$Start_pos_cache = @strpos ( $subject, $Beginmark_str, $Start_pos_cache );

/* this is possible start for range */

if (is_int ( $Start_pos_cache )) {

/* skip */

$Start_pos_cache = ($Start_pos_cache + $Beginmark_str_len);

/* test possible range start pos */

if (is_int ( $Begin_firstOccurence_pos )) {

if ($Start_pos_cache < $range_end_pos)

$rangeClean = 0;

elseif ($Start_pos_cache > $range_end_pos)

$rangeClean = 1;

}

/* here it is */

if (! is_int ( $Begin_firstOccurence_pos ))

$Begin_firstOccurence_pos = $Start_pos_cache;

} /* VIGA NR 0 ALGUST EI OLE */

if (! is_int ( $Start_pos_cache )) {

/* !algus */

/* VIGA NR 1 ALGUSMARKI EI LEITUD : VIIMANE VOIMALIK ALGUS */

if (is_int ( $Begin_firstOccurence_pos ) and ($Start_pos_cache < $range_end_pos))

$rangeClean = 1;

else

return false;

}

if (is_int ( $Begin_firstOccurence_pos ) and ($rangeClean != 1)) {

if (! is_int ( $End_pos_cache ))

$End_sequel_pos = $Begin_firstOccurence_pos;

$End_pos_cache = strpos ( $subject, $Endmark_str, $End_sequel_pos );

/* ok */

if (is_int ( $End_pos_cache ) and ($rangeClean != 1)) {

$range_current_lenght = ($End_pos_cache - $Begin_firstOccurence_pos);

$End_sequel_pos = ($End_pos_cache + $Endmark_str_len);

$range_end_pos = $End_pos_cache;

}

/* VIGA NR 2 LOPPU EI LEITUD */

if (! is_int ( $End_pos_cache ))

if ($End_pos_cache == false)

return false;

}

} while ( $rangeClean < 1 );

if (is_int ( $Begin_firstOccurence_pos ) and is_int ( $range_current_lenght ))

$Range = substr ( $subject, $Begin_firstOccurence_pos, $range_current_lenght );

else

return false;

return array (

'range' => $Range,

'begin' => $Begin_firstOccurence_pos,

'end' => $End_sequel_pos

);

} // end getrange()

} // class

?>

python解析mht文件_php解析mht文件转换成html的实例详解相关推荐

  1. python如何调用文件进行换位加密_python 换位密码算法的实例详解

    python 换位密码算法的实例详解 一前言: 换位密码基本原理:先把明文按照固定长度进行分组,然后对每一组的字符进行换位操作,从而实现加密.例如,字符串"Error should neve ...

  2. python从date目录导入数据集_PyTorch加载自己的数据集实例详解

    数据预处理在解决深度学习问题的过程中,往往需要花费大量的时间和精力. 数据处理的质量对训练神经网络来说十分重要,良好的数据处理不仅会加速模型训练, 更会提高模型性能.为解决这一问题,PyTorch提供 ...

  3. python 录制web视频_Python django框架 web端视频加密的实例详解

    视频加密流程图: 后端获取保利威的视频播放授权token,提供接口api给前端 参考文档:http://dev.polyv.net/2019/videoproduct/v-api/v-api-play ...

  4. python 时分秒毫秒_python将时分秒转换成秒的实例

    处理数据的时候遇到一个问题,从数据库里导出的数据是时分秒的格式:hh:mm:ss ,现在我需要把它转换成秒,方便计算. 原数据可能分两种情况,字段有可能是文本字符串类型的,也有可能是时间类型,他们的处 ...

  5. html格式怎么转换mp4视频文件怎么打开吗,QSV文件怎么打开 qsv文件转换成mp4格式教程详解...

    很多朋友都有遇到过QSV视频文件无法打开的情况吧.今天本文主要分享一下QSV文件怎么打开,另外如果需要手机.电脑都可以轻松打开qsv文件,则还需要将QSV文件转换成MP4格式就可以了,下面具体来看看. ...

  6. python类的使用方法图解_Python3.5面向对象编程图文与实例详解

    本文实例讲述了Python3.5面向对象编程.分享给大家供大家参考,具体如下: 1.面向过程与面向对象的比较 (1)面向过程编程(procedural programming) 面向过程编程又被称为: ...

  7. python里遍历筛选xml文件_python xml.etree.ElementTree遍历xml所有节点实例详解

    python xml.etree.ElementTree遍历xml所有节点 XML文件内容: 代码: #-*- coding: UTF-8 -*- # 从文件中读取数据 import xml.etre ...

  8. python守护多线程_Python多线程Threading、子线程与守护线程实例详解

    线程Threading: python中多线程需要使用threading模块 线程的创建与运行: 1.直接调用threading的Thread类: 线程的创建:线程对象=thread.Thread(t ...

  9. python如何定义类_Python中类的定义、继承及使用对象实例详解

    本文实例讲述了Python中类的定义.继承及使用对象的方法.分享给大家供大家参考.具体分析如下: Python编程中类的概念可以比作是某种类型集合的描述,如"人类"可以被看作一个类 ...

最新文章

  1. java节假日api--关于节假日想到的
  2. console.log(text)打印不出来的值,用console.log(text.length)却打印出来长度为1?
  3. hibernate SQL查询COUNT函数
  4. Windows 1.0 to Windows 10
  5. Kubernetes 系列(三):Kubernetes使用Traefik Ingress暴露服务
  6. Nginx_环境搭建
  7. Tree Cutting POJ - 2378(树形DP)
  8. 【Python CheckiO 题解】Median
  9. java so jnienv_JNI初步(五)jni ndk 一个.so文件依赖另一个.so文件的写法
  10. FastJson的使用方法总结
  11. 开奖|八大福利,康康你中奖了没?
  12. 计算机通信基础ppt,计算机网络第2章 数据通信基础知识要点课件.ppt
  13. Group By和Order By的总结
  14. 阶段3 2.Spring_08.面向切面编程 AOP_3 spring基于XML的AOP-编写必要的代码
  15. 云服务器里存放数据安全吗
  16. python读excel表_怎么用python读取excel表格的数据
  17. LInux 的流量限制
  18. mysql中的comment_请问一下在mysql中的 COMMENT 有什么作用吗??
  19. 物联网实训室建设方案(2020完整版)
  20. 十五分钟水edusrc证书(小学生日记)

热门文章

  1. web自动化笔记九:验证码的处理方式
  2. R语言产生对角阵、次对角阵等矩阵及矩阵运算
  3. eclipse全文搜索多个关键字
  4. 处理图片有困难?分享一款在线图像处理软件给你
  5. electron-updater自动更新踩坑
  6. No such file or directory处理
  7. Android 仿美团大众字母索引实现
  8. 取出数组第一大和第二大元素
  9. XRAY项目--电荷积分放大器AD8488介绍
  10. 技术从业者的未来(2)