php解析mht,php解析mht文件转换成html的实例详解
下面小编就为大家带来一篇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.gxlcms.com/,+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,php解析mht文件转换成html的实例详解相关推荐
- python解析mht文件_php解析mht文件转换成html的实例详解
下面小编就为大家带来一篇php解析mht文件转换成html的实例.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 php解析mht文件,使用编辑器打开可以看到base64 ...
- html格式怎么转换mp4视频文件怎么打开吗,QSV文件怎么打开 qsv文件转换成mp4格式教程详解...
很多朋友都有遇到过QSV视频文件无法打开的情况吧.今天本文主要分享一下QSV文件怎么打开,另外如果需要手机.电脑都可以轻松打开qsv文件,则还需要将QSV文件转换成MP4格式就可以了,下面具体来看看. ...
- php解析mht,php解析mht文件转换成html的实例
php解析mht文件,使用编辑器打开可以看到base64编码所以,mht是可以转换成html的. /** * 针对Mht格式的文件进行解析 * 使用例子: * * function mhtmlPars ...
- php读取mht,php解析mht文件转换成html的实例
php解析mht文件转换成html的实例 发布于 2017-08-07 07:27:31 | 116 次阅读 | 评论: 0 | 来源: 网友投递 PHP开源脚本语言PHP(外文名: Hypertex ...
- 把java文件打包成.jar (jar命令详解)
把java文件打包成.jar (jar命令详解) 先打开命令提示符(win2000或在运行框里执行cmd命令,win98为DOS提示符),输入jar Chelp,然后回车(如果你盘上已经有了jdk1. ...
- java 输入流可以合并吗_Java 使用IO流实现大文件的分割与合并实例详解
java 使用IO流实现大文件的分割与合并 文件分割应该算一个比较实用的功能,举例子说明吧比如说:你有一个3G的文件要从一台电脑Copy到另一台电脑, 但是你的存储设备(比如SD卡)只有1G ,这个时 ...
- java文件打包jar文件_把java文件打包成.jar (jar命令详解)
把java文件打包成.jar (jar命令详解) 先打开命令提示符(win2000或在运行框里执行cmd命令,win98为DOS提示符),输入jar Chelp,然后回车(如果你盘上已经有了jdk1. ...
- java文件流 m.jb51.net_FasfDFS整合Java实现文件上传下载功能实例详解
今天使用Java代码实现文件的上传和下载.对此作者提供了Java API支持,下载fastdfs-client-java将源码添加到项目中.或者在Maven项目pom.xml文件中添加依赖 org.c ...
- JavaWeb实现文件上传下载功能实例详解
感谢原文作者分享,原文链接:http://www.jb51.net/article/96745.htm 这篇文章主要介绍了JavaWeb中的文件上传和下载功能的实现,在开发中,文件上传和下载功能是非常 ...
- 怎么把ppt弄成链接的形式_怎样制作ppt课件 如何将ppt转换成视频【图文详解】...
怎样制作ppt课件? Powerpoint做出来的东西叫演示文稿,它是一个文件,其格式后缀名为.ppt,或者也可以保存为.pdf.图片格式等,2010版本中可保存为视频格式.近年来,中国的PPT应用水 ...
最新文章
- 存clob为空的值_将网页文本(HTML)保存到ORACLE数据库CLOB字详解
- 腾讯天衍实验室联合微众银行研发医疗联邦学习 AI利器让脑卒中预测准确率达80%
- 五大晶元厂的内存型号命名方式
- TensorFlow模型保存和加载方法
- [转] 关于SQLSERVER2000卸载与出现挂起问题的解决
- linux安装软件时提示找不到镜像的问题:Couldn't resolve host 'mirrorlist.centos.org'
- mc穿越时空地图android,我的世界RPG地图穿越时空地图存档下载
- 新买win8更换win7的方法步骤
- 俯首甘为孺子牛上一句是什么
- L2-010. 排座位-PAT团体程序设计天梯赛GPLT(并查集)
- 简述STL中容器适配器的概念
- [C#/DevExpress]VS2010使用CefSharp调用Chrome内核打开网页
- 计算机键盘上的符号英语怎么说,电脑键盘上特殊符号和标点符号名称的输入方法汇总...
- 新型脑刺激疗法治疗重度抑郁症
- Android 获取本地视频列表
- NGUI完美高性能无限滚动
- java获取手机通讯录权限_android获取手机通讯录
- svg果冻弹性按钮动画js特效
- windows网络服务
- 老二牛车Axure夜话:程序员眼中的原型设计视频教程之书到用时方恨少