php解析mht,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,[email protected],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的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持程序员学习网。
这就是微学网-程序员之家为你提供的"php解析mht文件转换成html的实例"希望对你有所帮助.本文来自网络,转载请注明出处:http://www.weixuecn.cn/article/6934.html
php解析mht,php解析mht文件转换成html的实例相关推荐
- python解析mht文件_php解析mht文件转换成html的实例详解
下面小编就为大家带来一篇php解析mht文件转换成html的实例.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 php解析mht文件,使用编辑器打开可以看到base64 ...
- php读取mht,php解析mht文件转换成html的实例
php解析mht文件转换成html的实例 发布于 2017-08-07 07:27:31 | 116 次阅读 | 评论: 0 | 来源: 网友投递 PHP开源脚本语言PHP(外文名: Hypertex ...
- python解析mht文件_php解析mht文件转换成html的方法
本篇文章主要介绍php解析mht文件转换成html的方法,感兴趣的朋友参考下,希望对大家有所帮助. php解析mht文件,使用编辑器打开可以看到base64编码所以,mht是可以转换成html的. / ...
- 小白学习PYTHON之路---PY文件转换成EXE可执行文件
一.背景 今天闲着无事,写了一个小小的Python脚本程序,然后给同学炫耀的时候,发现每次都得拉着其他人过来看着自己的电脑屏幕,感觉不是很爽,然后我想着网上肯定有关于Python脚本转换成可执行文件的 ...
- 使用ffmpeg进行视频文件转换成FLV整理
本系列文章导航 Windows下FFmpeg快速入门 ffmpeg参数解释 mencoder和ffmpeg参数详解(Java处理视频) Java 生成视频缩略图(ffmpeg) 使用ffmpeg进行视 ...
- Matlab pcode p文件 p代码 p文件代转m文件 被加密的p文件转换成.m文件
Matlab pcode p文件 p代码 p文件代转m文件 被加密的p文件转换成.m文件 前言 在我们使用MATLAB时候,通常会用到一些M脚本进行辅助使用,缩短了我们在平常工作时候的效率,但是M脚本 ...
- 怎么把jpg文件转换成pdf文件
怎么把jpg文件转换成pdf文件 PDF转换成Word文档对我们来讲并不生僻,假设文字是由一张张图片构成的,碰着这种状况怎么办,怎么将JPG转换成PDF?菜鸟损耗了不少工夫和肉体才找到一款好用的JPG ...
- JAVA如何实现将用户上传的PDF文件转换成图片并返回给用户
很多曾经攻克过的难题都没有及时记录并分享,觉得有些可惜.趁着现在还单身,头还没秃,精力也还算旺盛,我便整理出一些自己曾经挑灯夜战.独立实现的还算有些成就感的项目需求,记录在个人博客上,希望能给拥有相同 ...
- Java使用aspse实现Excel文件转换成PDF文件
使用Java代码把Excel文件转换成PDF文件 需要引用aspose包,引入操作我写了一个博客,地址如下 https://blog.csdn.net/weixin_46713508/article/ ...
最新文章
- java工程化_(二)Java工程化--Maven实践(示例代码)
- linux嵌入式平台测试,protobuf-c 在arm linux 嵌入式平台的使用 测试
- 【月薪三万】听说深圳老师工资全国最高!!!比德国还高
- scala spark 数据对比_Spark 实践——用 Scala 和 Spark 进行数据分析
- u深度重装系统详细教程_u深度u盘启动盘装win10教程
- 上古计算机语言,微软开源其上古编程语言GW-BASIC
- 变维分形预测matlab,【求助】请大家帮我该该求一维曲线分形维数的matlba程序好吗!!...
- Windows 提权
- 电脑显示受限制无连接应该怎么办
- 百度统计的使用技巧_SEO建议
- 根据项目或WBS结算规则批量生成下阶WBS的结算规则-CJB2
- 我读猫扑的《大王直言拷问网络写手良心》
- MySQL相关面试题总结
- 安装QQ的时候,页面显示创建文件夹失败,无法正常安装,请尝试选择新的安装目录
- 中国基金业协会网站资产管理业务综合报送平台-数据爬取
- RedisTemplate报错WRONGTYPE Operation against a key holding the wrong kind of value
- Windows下MySQL5.5安装,配置与卸载
- kaldi中的深度神经网络
- 师傅带徒弟学:Python正则表达式-关东升-专题视频课程
- swagger导出到pdf、html文档
热门文章
- java制作霓虹灯_PS进阶教程!教你打造效果超逼真的动态闪烁霓虹灯
- PPPwizard1.4.3软件使用说明中文翻译稿
- 2022最新淘宝天猫商品评论采集
- 【华为机试真题Java】从入门到入职-真题列表导读
- 破解微信图片防盗链 微信图片不显示怎么办?
- gem 安装oxidized-web报错:checking for -licui18n... no处理
- Oxidized-20180912-docker 版本的网络设备备份系统
- ZeroDivisionError:Integer division or modulo by zero
- 使用UltraISO刻录DMG光盘映像
- C/C++ 余弦函数 cos - C语言零基础入门教程