php解析mht文件转换成html的实例

发布于 2017-08-07 07:27:31 | 116 次阅读 | 评论: 0 | 来源: 网友投递

PHP开源脚本语言PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。

下面小编就为大家带来一篇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.hot.ee/ukjoesaar,+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

?>

以上这篇php解析mht文件转换成html的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持PHPERZ。

相关阅读:

php解析mht文件转换成html的实例

php将图片文件转换成二进制输出的方法

php将文本文件转换csv输出的方法

PHP将HTML转换成文本的实现代码

php将数组转换成csv格式文件输出的方法

php实现将wav文件转换成图像文件并在页面中显示的方法

分享php代码将360浏览器导出的favdb的sqlite数据库文件转换为html

PHP把JPEG图片转换成Progressive JPEG的方法

php导出csv格式数据并将数字转换成文本的思路以及代码示例

php中将汉字转换成拼音的函数代码

php将字符串全部转换成大写或者小写的方法

php实现字符串首字母转换成大写的方法

php读取mht,php解析mht文件转换成html的实例相关推荐

  1. php解析mht,php解析mht文件转换成html的实例

    php解析mht文件,使用编辑器打开可以看到base64编码所以,mht是可以转换成html的. /** * 针对Mht格式的文件进行解析 * 使用例子: * * function mhtmlPars ...

  2. python解析mht文件_php解析mht文件转换成html的实例详解

    下面小编就为大家带来一篇php解析mht文件转换成html的实例.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 php解析mht文件,使用编辑器打开可以看到base64 ...

  3. python解析mht文件_php解析mht文件转换成html的方法

    本篇文章主要介绍php解析mht文件转换成html的方法,感兴趣的朋友参考下,希望对大家有所帮助. php解析mht文件,使用编辑器打开可以看到base64编码所以,mht是可以转换成html的. / ...

  4. Matlab实现 把.tdms文件转换成.mat文件,并读取分割成等长信号数据集

    ①将接收到的.tdms文件转换成.mat clc clearData = convertTDMS(true,'xxx.tdms'); % 将.tdms生成.mat文件 % Data = load('x ...

  5. Java使用aspse实现Excel文件转换成PDF文件

    使用Java代码把Excel文件转换成PDF文件 需要引用aspose包,引入操作我写了一个博客,地址如下 https://blog.csdn.net/weixin_46713508/article/ ...

  6. 将名为“普通高等学校本科专业目录.pdf”的pdf文件转换成csv文件

    文章目录 任务描述 2023年普通高等学校本科专业目录pdf链接 代码 代码解析 运行截图 任务描述 将名为"普通高等学校本科专业目录.pdf"的pdf文件转换成csv文件.这个p ...

  7. Java使用aspose把PDF文件转换成PNG文件,以及把PDF文件水印转换成PNG格式

    Java代码把PDF文件转换成PNG文件 需要引用aspose包,引入操作我写了一个博客,地址如下 https://blog.csdn.net/weixin_46713508/article/deta ...

  8. xpdf将pdf转换为html,(WordExcelPDF文件转换成HTML整理.docx

    (WordExcelPDF文件转换成HTML整理 项目开发过程中,需求涉及到了各种文档转换为HTML或者网页易显示格式,现在将实现方式整理如下:?一.使用Jacob转换Word,Excel为HTML? ...

  9. python将txt转换为csv_Python Pandas 三行代码将 txt 文件转换成 csv 文件

    今天需要处理几个比较大的 txt 文件,每个文件都在 2GB 以上,直接用 Excel 将其转换成 csv 文件显然是不太可行的,于是用 Python 中的数据处理神器 Pandas,三行代码就能搞定 ...

最新文章

  1. Python3算法基础练习:编程100例( 26 ~ 30)
  2. Http上传Xml文件
  3. mysql约束添加删除数据_mysql中约束的添加,修改,与删除
  4. 初学WEB前端的建议,你不看给别人可惜了!
  5. JavaScript学习——JavaScript 循环
  6. JSON文件导入Unity3d中是空的的问题
  7. 性别年龄论文阅读(3)——VGGFace2
  8. 三分钟教你开通支付宝收款二维码
  9. C++实现控制台迷宫小游戏
  10. jQuery之动画的淡入淡出效果
  11. 代季峰对话张祥雨 | 自动驾驶感知新时代!新一代环视感知算法BEVFormer有哪些优势...
  12. 上海航芯 | 全自动咖啡机设计方案
  13. 东半球最好的SecureCRT高级教程
  14. 分部积分出现积回去的情况
  15. 办公技巧——PPT添加页码
  16. (附源码)ssm无人机数据管理系统 毕业设计 111022
  17. 对于同源与非同源的理解
  18. VR垃圾分类游戏的“入门”场景|广州华锐互动
  19. Java用普里姆算法(prim)解决修路最短路径问题
  20. Java练习题-09

热门文章

  1. Xshell无法启动问题解决
  2. c++操作xml文件
  3. 搜索总结)(深搜和广搜)
  4. 百度商家口碑将停止运营并下线
  5. 数据推荐 | 手势识别训练数据集
  6. 多代理强化学习MARL(MADDPG,Minimax-Q,Nash Q-Learning)
  7. unity3D中导入的物体锚点居中
  8. 点击按钮页面滚动到对应位置(锚点)
  9. 2023年3月华为HCIA认证新增题库(H12-811)
  10. java.lang.NullPointerException: pattern